Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
2f1dbf5a
Commit
2f1dbf5a
authored
Nov 10, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(python): добавил отдельную функцию проверки корректности параметров
в UInterface, добавил отдельное исключение UValidateError, в случае неверных аргументов.
parent
8baac8a9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
196 additions
and
18 deletions
+196
-18
UInterface.py
python/lib/UInterface.py
+46
-12
UExceptions.h
python/lib/pyUniSet/UExceptions.h
+8
-0
UExceptions_wrap.cxx
python/lib/pyUniSet/UExceptions_wrap.cxx
+118
-4
pyUExceptions.py
python/lib/pyUniSet/pyUExceptions.py
+22
-0
testUC.py
python/tests/UConnector/testUC.py
+2
-2
No files found.
python/lib/UInterface.py
View file @
2f1dbf5a
...
...
@@ -12,7 +12,7 @@ class UInterface():
def
__init__
(
self
):
self
.
u
type
=
""
self
.
i
type
=
""
self
.
i
=
None
self
.
ignore_nodes
=
False
...
...
@@ -30,6 +30,9 @@ class UInterface():
self
.
i
=
UModbus
()
self
.
itype
=
"modbus"
def
getIType
(
self
):
return
self
.
itype
# return [id,node,name]
def
getIDinfo
(
self
,
s_id
):
...
...
@@ -42,6 +45,37 @@ class UInterface():
return
[
""
,
""
,
""
]
# return [ RESULT, ERROR ]
def
validateParam
(
self
,
s_id
):
try
:
if
self
.
itype
==
"uniset"
:
s
=
to_sid
(
s_id
,
self
.
i
)
if
s
[
0
]
==
DefaultID
:
return
[
False
,
"Unknown ID for '
%
s'"
%
str
(
s_id
)]
return
[
True
,
""
]
if
self
.
itype
==
"modbus"
:
mbaddr
,
mbreg
,
mbfunc
,
nbit
,
vtype
=
get_mbquery_param
(
s_id
,
"0x04"
)
err
=
[]
if
mbaddr
==
None
:
err
.
append
(
"Unknown mbaddr"
)
if
mbfunc
==
None
:
err
.
append
(
"Unknown mbfunc"
)
if
mbreg
==
None
:
err
.
append
(
"Unknown mbreg"
)
if
len
(
err
)
>
0
:
return
[
False
,
', '
.
join
(
err
)]
return
[
True
,
""
]
except
UException
,
e
:
return
[
False
,
"
%
s"
%
e
.
getError
()]
raise
[
False
,
"Unknown interface
%
s"
%
self
.
itype
]
def
getValue
(
self
,
s_id
):
try
:
...
...
@@ -55,17 +89,17 @@ class UInterface():
if
self
.
itype
==
"modbus"
:
mbaddr
,
mbreg
,
mbfunc
,
nbit
,
vtype
=
get_mbquery_param
(
s_id
,
"0x04"
)
if
mbaddr
==
None
or
mbreg
==
None
or
mbfunc
==
None
:
raise
U
Exception
(
"(modbus:getValue): parse id='
%
s' failed. Must be 'mbreg@mbaddr:mbfunc:nbit:vtype'"
%
s_id
)
raise
U
ValidateError
(
"(modbus:getValue): parse id='
%
s' failed. Must be 'mbreg@mbaddr:mbfunc:nbit:vtype'"
%
s_id
)
if
self
.
i
.
isWriteFunction
(
mbfunc
)
==
True
:
raise
U
Exception
(
"(modbus:getValue): for id='
%
s' mbfunc=
%
d is WriteFunction. Must be 'read'."
%
(
s_id
,
mbfunc
)
)
raise
U
ValidateError
(
"(modbus:getValue): for id='
%
s' mbfunc=
%
d is WriteFunction. Must be 'read'."
%
(
s_id
,
mbfunc
)
)
return
self
.
i
.
mbread
(
mbaddr
,
mbreg
,
mbfunc
,
vtype
,
nbit
)
except
UException
,
e
:
raise
e
raise
U
Exception
(
"(getValue): Unknown interface
%
s"
%
self
.
u
type
)
raise
U
ValidateError
(
"(getValue): Unknown interface
%
s"
%
self
.
i
type
)
def
setValue
(
self
,
s_id
,
s_val
,
supplier
=
DefaultSupplerID
):
try
:
...
...
@@ -81,11 +115,11 @@ class UInterface():
# ip,port,mbaddr,mbreg,mbfunc,vtype,nbit = ui.get_modbus_param(s_id)
mbaddr
,
mbreg
,
mbfunc
,
nbit
,
vtype
=
get_mbquery_param
(
s_id
,
"0x06"
)
if
mbaddr
==
None
or
mbreg
==
None
or
mbfunc
==
None
:
raise
U
Exception
(
"(modbus:setValue): parse id='
%
s' failed. Must be 'mbreg@mbaddr:mbfunc'"
%
s_id
)
raise
U
ValidateError
(
"(modbus:setValue): parse id='
%
s' failed. Must be 'mbreg@mbaddr:mbfunc'"
%
s_id
)
#print "MODBUS SET VALUE: s_id=%s"%s_id
if
self
.
i
.
isWriteFunction
(
mbfunc
)
==
False
:
raise
U
Exception
(
"(modbus:setValue): for id='
%
s' mbfunc=
%
d is NOT WriteFunction."
%
(
s_id
,
mbfunc
)
)
raise
U
ValidateError
(
"(modbus:setValue): for id='
%
s' mbfunc=
%
d is NOT WriteFunction."
%
(
s_id
,
mbfunc
)
)
self
.
i
.
mbwrite
(
mbaddr
,
mbreg
,
to_int
(
s_val
),
mbfunc
)
return
...
...
@@ -93,7 +127,7 @@ class UInterface():
except
UException
,
e
:
raise
e
raise
U
Exception
(
"(setValue): Unknown interface
%
s"
%
self
.
u
type
)
raise
U
ValidateError
(
"(setValue): Unknown interface
%
s"
%
self
.
i
type
)
def
getConfFileName
(
self
):
if
self
.
itype
==
"uniset"
:
...
...
@@ -102,7 +136,7 @@ class UInterface():
if
self
.
itype
==
"modbus"
:
return
""
raise
U
Exception
(
"(setValue): Unknown interface
%
s"
%
self
.
u
type
)
raise
U
ValidateError
(
"(setValue): Unknown interface
%
s"
%
self
.
i
type
)
def
getShortName
(
self
,
s_node
):
if
self
.
itype
==
"uniset"
:
...
...
@@ -111,7 +145,7 @@ class UInterface():
if
self
.
itype
==
"modbus"
:
return
""
raise
U
Exception
(
"(getShortName): Unknown interface
%
s"
%
self
.
u
type
)
raise
U
ValidateError
(
"(getShortName): Unknown interface
%
s"
%
self
.
i
type
)
def
getNodeID
(
self
,
s_node
):
if
self
.
itype
==
"uniset"
:
...
...
@@ -120,7 +154,7 @@ class UInterface():
if
self
.
itype
==
"modbus"
:
return
None
raise
U
Exception
(
"(getNodeID): Unknown interface
%
s"
%
self
.
u
type
)
raise
U
ValidateError
(
"(getNodeID): Unknown interface
%
s"
%
self
.
i
type
)
def
getSensorID
(
self
,
s_name
):
if
self
.
itype
==
"uniset"
:
...
...
@@ -129,7 +163,7 @@ class UInterface():
if
self
.
itype
==
"modbus"
:
return
None
raise
U
Exception
(
"(getSensorID): Unknown interface
%
s"
%
self
.
u
type
)
raise
U
ValidateError
(
"(getSensorID): Unknown interface
%
s"
%
self
.
i
type
)
def
getObjectID
(
self
,
o_name
):
if
self
.
itype
==
"uniset"
:
...
...
@@ -138,5 +172,5 @@ class UInterface():
if
self
.
itype
==
"modbus"
:
return
None
raise
U
Exception
(
"(getObjectID): Unknown interface
%
s"
%
self
.
u
type
)
raise
U
ValidateError
(
"(getObjectID): Unknown interface
%
s"
%
self
.
i
type
)
python/lib/pyUniSet/UExceptions.h
View file @
2f1dbf5a
...
...
@@ -48,5 +48,13 @@ struct USysError:
~
USysError
()
{}
};
//---------------------------------------------------------------------------
struct
UValidateError
:
public
UException
{
UValidateError
()
:
UException
(
"UValidateError"
)
{}
explicit
UValidateError
(
const
std
::
string
&
e
)
:
UException
(
e
)
{}
~
UValidateError
()
{}
};
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
python/lib/pyUniSet/UExceptions_wrap.cxx
View file @
2f1dbf5a
...
...
@@ -3010,9 +3010,10 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) {
#define SWIGTYPE_p_UException swig_types[0]
#define SWIGTYPE_p_USysError swig_types[1]
#define SWIGTYPE_p_UTimeOut swig_types[2]
#define SWIGTYPE_p_char swig_types[3]
static
swig_type_info
*
swig_types
[
5
];
static
swig_module_info
swig_module
=
{
swig_types
,
4
,
0
,
0
,
0
,
0
};
#define SWIGTYPE_p_UValidateError swig_types[3]
#define SWIGTYPE_p_char swig_types[4]
static
swig_type_info
*
swig_types
[
6
];
static
swig_module_info
swig_module
=
{
swig_types
,
5
,
0
,
0
,
0
,
0
};
#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
...
...
@@ -3727,6 +3728,109 @@ SWIGINTERN PyObject *USysError_swigregister(PyObject *SWIGUNUSEDPARM(self), PyOb
return
SWIG_Py_Void
();
}
SWIGINTERN
PyObject
*
_wrap_new_UValidateError__SWIG_0
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UValidateError
*
result
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
":new_UValidateError"
))
SWIG_fail
;
result
=
(
UValidateError
*
)
new
UValidateError
();
resultobj
=
SWIG_NewPointerObj
(
SWIG_as_voidptr
(
result
),
SWIGTYPE_p_UValidateError
,
SWIG_POINTER_NEW
|
0
);
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_new_UValidateError__SWIG_1
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
std
::
string
*
arg1
=
0
;
int
res1
=
SWIG_OLDOBJ
;
PyObject
*
obj0
=
0
;
UValidateError
*
result
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:new_UValidateError"
,
&
obj0
))
SWIG_fail
;
{
std
::
string
*
ptr
=
(
std
::
string
*
)
0
;
res1
=
SWIG_AsPtr_std_string
(
obj0
,
&
ptr
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"new_UValidateError"
"', argument "
"1"" of type '"
"std::string const &""'"
);
}
if
(
!
ptr
)
{
SWIG_exception_fail
(
SWIG_ValueError
,
"invalid null reference "
"in method '"
"new_UValidateError"
"', argument "
"1"" of type '"
"std::string const &""'"
);
}
arg1
=
ptr
;
}
result
=
(
UValidateError
*
)
new
UValidateError
((
std
::
string
const
&
)
*
arg1
);
resultobj
=
SWIG_NewPointerObj
(
SWIG_as_voidptr
(
result
),
SWIGTYPE_p_UValidateError
,
SWIG_POINTER_NEW
|
0
);
if
(
SWIG_IsNewObj
(
res1
))
delete
arg1
;
return
resultobj
;
fail
:
if
(
SWIG_IsNewObj
(
res1
))
delete
arg1
;
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_new_UValidateError
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_ssize_t
argc
;
PyObject
*
argv
[
2
]
=
{
0
};
Py_ssize_t
ii
;
if
(
!
PyTuple_Check
(
args
))
SWIG_fail
;
argc
=
args
?
PyObject_Length
(
args
)
:
0
;
for
(
ii
=
0
;
(
ii
<
1
)
&&
(
ii
<
argc
);
ii
++
)
{
argv
[
ii
]
=
PyTuple_GET_ITEM
(
args
,
ii
);
}
if
(
argc
==
0
)
{
return
_wrap_new_UValidateError__SWIG_0
(
self
,
args
);
}
if
(
argc
==
1
)
{
int
_v
;
int
res
=
SWIG_AsPtr_std_string
(
argv
[
0
],
(
std
::
string
**
)(
0
));
_v
=
SWIG_CheckState
(
res
);
if
(
_v
)
{
return
_wrap_new_UValidateError__SWIG_1
(
self
,
args
);
}
}
fail
:
SWIG_SetErrorMsg
(
PyExc_NotImplementedError
,
"Wrong number or type of arguments for overloaded function 'new_UValidateError'.
\n
"
" Possible C/C++ prototypes are:
\n
"
" UValidateError::UValidateError()
\n
"
" UValidateError::UValidateError(std::string const &)
\n
"
);
return
0
;
}
SWIGINTERN
PyObject
*
_wrap_delete_UValidateError
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UValidateError
*
arg1
=
(
UValidateError
*
)
0
;
void
*
argp1
=
0
;
int
res1
=
0
;
PyObject
*
obj0
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:delete_UValidateError"
,
&
obj0
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UValidateError
,
SWIG_POINTER_DISOWN
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"delete_UValidateError"
"', argument "
"1"" of type '"
"UValidateError *""'"
);
}
arg1
=
reinterpret_cast
<
UValidateError
*
>
(
argp1
);
delete
arg1
;
resultobj
=
SWIG_Py_Void
();
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
UValidateError_swigregister
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
obj
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:swigregister"
,
&
obj
))
return
NULL
;
SWIG_TypeNewClientData
(
SWIGTYPE_p_UValidateError
,
SWIG_NewClientData
(
obj
));
return
SWIG_Py_Void
();
}
static
PyMethodDef
SwigMethods
[]
=
{
{
(
char
*
)
"SWIG_PyInstanceMethod_New"
,
(
PyCFunction
)
SWIG_PyInstanceMethod_New
,
METH_O
,
NULL
},
{
(
char
*
)
"new_UException"
,
_wrap_new_UException
,
METH_VARARGS
,
NULL
},
...
...
@@ -3741,6 +3845,9 @@ static PyMethodDef SwigMethods[] = {
{
(
char
*
)
"new_USysError"
,
_wrap_new_USysError
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"delete_USysError"
,
_wrap_delete_USysError
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"USysError_swigregister"
,
USysError_swigregister
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"new_UValidateError"
,
_wrap_new_UValidateError
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"delete_UValidateError"
,
_wrap_delete_UValidateError
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UValidateError_swigregister"
,
UValidateError_swigregister
,
METH_VARARGS
,
NULL
},
{
NULL
,
NULL
,
0
,
NULL
}
};
...
...
@@ -3753,27 +3860,34 @@ static void *_p_UTimeOutTo_p_UException(void *x, int *SWIGUNUSEDPARM(newmemory))
static
void
*
_p_USysErrorTo_p_UException
(
void
*
x
,
int
*
SWIGUNUSEDPARM
(
newmemory
))
{
return
(
void
*
)((
UException
*
)
((
USysError
*
)
x
));
}
static
void
*
_p_UValidateErrorTo_p_UException
(
void
*
x
,
int
*
SWIGUNUSEDPARM
(
newmemory
))
{
return
(
void
*
)((
UException
*
)
((
UValidateError
*
)
x
));
}
static
swig_type_info
_swigt__p_UException
=
{
"_p_UException"
,
"UException *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
_swigt__p_USysError
=
{
"_p_USysError"
,
"USysError *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
_swigt__p_UTimeOut
=
{
"_p_UTimeOut"
,
"UTimeOut *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
_swigt__p_UValidateError
=
{
"_p_UValidateError"
,
"UValidateError *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
_swigt__p_char
=
{
"_p_char"
,
"char *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
*
swig_type_initial
[]
=
{
&
_swigt__p_UException
,
&
_swigt__p_USysError
,
&
_swigt__p_UTimeOut
,
&
_swigt__p_UValidateError
,
&
_swigt__p_char
,
};
static
swig_cast_info
_swigc__p_UException
[]
=
{
{
&
_swigt__p_UException
,
0
,
0
,
0
},
{
&
_swigt__p_UTimeOut
,
_p_UTimeOutTo_p_UException
,
0
,
0
},
{
&
_swigt__p_USysError
,
_p_USysErrorTo_p_UException
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_UException
[]
=
{
{
&
_swigt__p_UException
,
0
,
0
,
0
},
{
&
_swigt__p_UTimeOut
,
_p_UTimeOutTo_p_UException
,
0
,
0
},
{
&
_swigt__p_USysError
,
_p_USysErrorTo_p_UException
,
0
,
0
},
{
&
_swigt__p_UValidateError
,
_p_UValidateErrorTo_p_UException
,
0
,
0
},
{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_USysError
[]
=
{
{
&
_swigt__p_USysError
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_UTimeOut
[]
=
{
{
&
_swigt__p_UTimeOut
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_UValidateError
[]
=
{
{
&
_swigt__p_UValidateError
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_char
[]
=
{
{
&
_swigt__p_char
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
*
swig_cast_initial
[]
=
{
_swigc__p_UException
,
_swigc__p_USysError
,
_swigc__p_UTimeOut
,
_swigc__p_UValidateError
,
_swigc__p_char
,
};
...
...
python/lib/pyUniSet/pyUExceptions.py
View file @
2f1dbf5a
...
...
@@ -140,6 +140,28 @@ class USysError(UException):
USysError_swigregister
=
_pyUExceptions
.
USysError_swigregister
USysError_swigregister
(
USysError
)
class
UValidateError
(
UException
):
__swig_setmethods__
=
{}
for
_s
in
[
UException
]:
__swig_setmethods__
.
update
(
getattr
(
_s
,
'__swig_setmethods__'
,
{}))
__setattr__
=
lambda
self
,
name
,
value
:
_swig_setattr
(
self
,
UValidateError
,
name
,
value
)
__swig_getmethods__
=
{}
for
_s
in
[
UException
]:
__swig_getmethods__
.
update
(
getattr
(
_s
,
'__swig_getmethods__'
,
{}))
__getattr__
=
lambda
self
,
name
:
_swig_getattr
(
self
,
UValidateError
,
name
)
__repr__
=
_swig_repr
def
__init__
(
self
,
*
args
):
this
=
_pyUExceptions
.
new_UValidateError
(
*
args
)
try
:
self
.
this
.
append
(
this
)
except
Exception
:
self
.
this
=
this
__swig_destroy__
=
_pyUExceptions
.
delete_UValidateError
__del__
=
lambda
self
:
None
UValidateError_swigregister
=
_pyUExceptions
.
UValidateError_swigregister
UValidateError_swigregister
(
UValidateError
)
# This file is compatible with both classic and new-style classes.
python/tests/UConnector/testUC.py
View file @
2f1dbf5a
...
...
@@ -38,8 +38,8 @@ if __name__ == "__main__":
uc1
=
UConnector
(
lst
,
"test.xml"
)
uc2
=
UConnector
(
lst2
,
"test.xml"
)
obj1
=
UProxyObject
(
"TestProc"
,
uc1
.
getConfID
()
)
obj2
=
UProxyObject
(
"TestProc1"
,
uc2
.
getConfID
()
)
obj1
=
UProxyObject
(
"TestProc"
)
obj2
=
UProxyObject
(
"TestProc1"
)
# print "(0)UIType: %s" % uc1.getUIType()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment