Commit 2f3b88c8 authored by Pavel Vainerman's avatar Pavel Vainerman

Попытка добиться работы from uniset import *

parent 5d449bc8
...@@ -6,7 +6,7 @@ import time ...@@ -6,7 +6,7 @@ import time
import sys import sys
def is_id( str_id ): def is_id( str_id ):
if str_id.__class__.__name__ == "int" or str_id.__class__.__name__ == "long": if isinstance(str_id,int) or isinstance(str_id,long):
return True return True
if str_id.strip().isdigit(): if str_id.strip().isdigit():
...@@ -19,9 +19,12 @@ def to_int(s): ...@@ -19,9 +19,12 @@ def to_int(s):
if s == None or s == "": if s == None or s == "":
return 0 return 0
if s.__class__.__name__ == "int" or s.__class__.__name__ == "long": if isinstance(s,int) or isinstance(s,long):
return s return s
if isinstance(s,float):
return int(s)
if len(s)>2 and s[0] == '0' and s[1] == 'x': if len(s)>2 and s[0] == '0' and s[1] == 'x':
return int(s,16) return int(s,16)
...@@ -32,7 +35,7 @@ def to_int(s): ...@@ -32,7 +35,7 @@ def to_int(s):
return 0 return 0
return int(s.strip()) return int(s.strip())
def to_str(s_val): def to_str(s_val):
if s_val == None: if s_val == None:
...@@ -57,17 +60,17 @@ def get_sinfo(raw, sep='@'): ...@@ -57,17 +60,17 @@ def get_sinfo(raw, sep='@'):
def to_sid(str_id, ui): def to_sid(str_id, ui):
if str_id == None or str_id == "": if str_id == None or str_id == "":
return [DefaultID,DefaultID,""] return [DefaultID,DefaultID,""]
if is_id(str_id): if is_id(str_id):
return [int(str_id),DefaultID,ui.getShortName(int(str_id))] return [int(str_id),DefaultID,ui.getShortName(int(str_id))]
s = get_sinfo(str_id) s = get_sinfo(str_id)
s_id = s[0] s_id = s[0]
s_node = s[1] s_node = s[1]
if s_id == "": if s_id == "":
return [DefaultID,DefaultID,"?@?"] return [DefaultID,DefaultID,"?@?"]
s_name = "" s_name = ""
if is_id(s_id): if is_id(s_id):
s_id = int(s_id) s_id = int(s_id)
...@@ -75,10 +78,10 @@ def to_sid(str_id, ui): ...@@ -75,10 +78,10 @@ def to_sid(str_id, ui):
else: else:
s_name = s_id s_name = s_id
s_id = ui.getSensorID(s_id) s_id = ui.getSensorID(s_id)
if s_node == "": if s_node == "":
return [s_id,DefaultID,s_name] return [s_id,DefaultID,s_name]
n_name = "" n_name = ""
if is_id(s_node): if is_id(s_node):
s_node = int(s_node) s_node = int(s_node)
...@@ -86,15 +89,15 @@ def to_sid(str_id, ui): ...@@ -86,15 +89,15 @@ def to_sid(str_id, ui):
else: else:
n_name = s_node n_name = s_node
s_node = ui.getNodeID(s_node) s_node = ui.getNodeID(s_node)
return [s_id,s_node,str(s_name+"@"+n_name)] return [s_id,s_node,str(s_name+"@"+n_name)]
# Получение списка пар [id@node,int(val)] из строки "id1@node1=val1,id2=val2,.." # Получение списка пар [id@node,int(val)] из строки "id1@node1=val1,id2=val2,.."
def get_int_list(raw_str,sep='='): def get_int_list(raw_str,sep='='):
if raw_str == None or raw_str == "": if raw_str == None or raw_str == "":
return [] return []
slist = [] slist = []
l = raw_str.split(",") l = raw_str.split(",")
for s in l: for s in l:
...@@ -113,15 +116,15 @@ def list_to_str(lst,sep='='): ...@@ -113,15 +116,15 @@ def list_to_str(lst,sep='='):
res += ",%s=%s"%(v[0],v[1]) res += ",%s=%s"%(v[0],v[1])
else: else:
res += "%s=%s"%(v[0],v[1]) res += "%s=%s"%(v[0],v[1])
return res return res
# Получение списка пар [sX,kX] из строки "s1=k1,s2=k2,.." # Получение списка пар [sX,kX] из строки "s1=k1,s2=k2,.."
def get_str_list(raw_str,sep='='): def get_str_list(raw_str,sep='='):
if raw_str == None or raw_str == "": if raw_str == None or raw_str == "":
return [] return []
slist = [] slist = []
l = raw_str.split(",") l = raw_str.split(",")
for s in l: for s in l:
...@@ -135,7 +138,7 @@ def get_str_list(raw_str,sep='='): ...@@ -135,7 +138,7 @@ def get_str_list(raw_str,sep='='):
# Получение списка пар [key,val] из строки "key1:val1,key2:val2,.." # Получение списка пар [key,val] из строки "key1:val1,key2:val2,.."
def get_replace_list(raw_str): def get_replace_list(raw_str):
if raw_str == None or raw_str == "": if raw_str == None or raw_str == "":
return [] return []
slist = [] slist = []
...@@ -150,7 +153,7 @@ def get_replace_list(raw_str): ...@@ -150,7 +153,7 @@ def get_replace_list(raw_str):
print "(get_replace_list:WARNING): (v:x) undefined value for " + str(s) print "(get_replace_list:WARNING): (v:x) undefined value for " + str(s)
key = to_str(v[0]).strip().strip("\n") key = to_str(v[0]).strip().strip("\n")
slist.append([key,0]) slist.append([key,0])
return slist return slist
# Парсинг строки вида hostname:port # Парсинг строки вида hostname:port
...@@ -205,7 +208,7 @@ def get_mbquery_param( raw_str, def_mbfunc="0x04", ret_str=False ): ...@@ -205,7 +208,7 @@ def get_mbquery_param( raw_str, def_mbfunc="0x04", ret_str=False ):
if len(mbaddr) == 0 or len(mbreg) == 0 or len(mbfunc) == 0: if len(mbaddr) == 0 or len(mbreg) == 0 or len(mbfunc) == 0:
if ret_str == True: if ret_str == True:
return ["","","","",""] return ["","","","",""]
#print "(get_mbquery_param:WARNING): BAD STRING FORMAT! strig='%s'. Must be 'mbreg@mbaddr:mbfunc:nbit:vtype'"%(raw_str) #print "(get_mbquery_param:WARNING): BAD STRING FORMAT! strig='%s'. Must be 'mbreg@mbaddr:mbfunc:nbit:vtype'"%(raw_str)
return [None,None,None,None,None] return [None,None,None,None,None]
...@@ -228,9 +231,9 @@ def getArgParam(param,defval=""): ...@@ -228,9 +231,9 @@ def getArgParam(param,defval=""):
return sys.argv[i+1] return sys.argv[i+1]
else: else:
break; break;
return defval return defval
def getArgInt(param,defval=0): def getArgInt(param,defval=0):
for i in range(0, len(sys.argv)): for i in range(0, len(sys.argv)):
if sys.argv[i] == param: if sys.argv[i] == param:
...@@ -238,12 +241,12 @@ def getArgInt(param,defval=0): ...@@ -238,12 +241,12 @@ def getArgInt(param,defval=0):
return to_int(sys.argv[i+1]) return to_int(sys.argv[i+1])
else: else:
break; break;
return defval return defval
def checkArgParam(param,defval=""): def checkArgParam(param,defval=""):
for i in range(0, len(sys.argv)): for i in range(0, len(sys.argv)):
if sys.argv[i] == param: if sys.argv[i] == param:
return True return True
return defval return defval
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from UInterface import * __all__=["UInterface","UGlobal","UniXML","pyUInterface","pyUniSet","pyUModbus","pyUConnector","pyUExceptions"]
from UGlobal import *
from UniXML import *
from pyUExceptions import * #from UInterface import *
from pyUniSet import * #from UGlobal import *
from pyUModbus import * #from UniXML import *
from pyUConnector import *
#from pyUInterface import *
#from pyUniSet import *
#from pyUModbus import *
#from pyUConnector import *
#from pyUExceptions import *
...@@ -2,18 +2,18 @@ if DISABLE_PYTHON ...@@ -2,18 +2,18 @@ if DISABLE_PYTHON
else else
python_SCRIPTS = pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py python_SCRIPTS = pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py
pyexec_LTLIBRARIES = _pyUConnector.la _pyUModbus.la _pyUExceptions.la _pyUniSet.la pyexec_LTLIBRARIES = _pyUConnector.la _pyUModbus.la _pyUExceptions.la _pyUniSet.la
_pyUniSet_la_SOURCES = pyUInterface.cc UInterface_wrap.cxx _pyUniSet_la_SOURCES = PyUInterface.cc UInterface_wrap.cxx
_pyUniSet_la_CXXFLAGS = $(UNISET_CFLAGS) $(PYTHON_CFLAGS) _pyUniSet_la_CXXFLAGS = $(UNISET_CFLAGS) $(PYTHON_CFLAGS)
_pyUniSet_la_LDFLAGS = -module -avoid-version _pyUniSet_la_LDFLAGS = -module -avoid-version
_pyUniSet_la_LIBADD = $(UNISET_LIBS) $(PYTHON_LIBS) _pyUniSet_la_LIBADD = $(UNISET_LIBS) $(PYTHON_LIBS)
UInterface_wrap.cxx: UInterface.i pyUInterface.h UInterface_wrap.cxx: UInterface.i PyUInterface.h
swig -python -c++ -classic UInterface.i swig -python -c++ -classic UInterface.i
_pyUConnector_la_SOURCES = UConnector.cc UConnector_wrap.cxx _pyUConnector_la_SOURCES = UConnector.cc UConnector_wrap.cxx
_pyUConnector_la_CXXFLAGS = $(UNISET_CFLAGS) $(PYTHON_CFLAGS) _pyUConnector_la_CXXFLAGS = $(UNISET_CFLAGS) $(PYTHON_CFLAGS)
_pyUConnector_la_LDFLAGS = -module -avoid-version _pyUConnector_la_LDFLAGS = -module -avoid-version
_pyUConnector_la_LIBADD = $(UNISET_LIBS) $(PYTHON_LIBS) _pyUConnector_la_LIBADD = $(UNISET_LIBS) $(PYTHON_LIBS)
...@@ -21,7 +21,7 @@ UConnector_wrap.cxx: UConnector.i UConnector.h ...@@ -21,7 +21,7 @@ UConnector_wrap.cxx: UConnector.i UConnector.h
swig -python -c++ -classic UConnector.i swig -python -c++ -classic UConnector.i
_pyUModbus_la_SOURCES = UModbus.cc UModbus_wrap.cxx _pyUModbus_la_SOURCES = UModbus.cc UModbus_wrap.cxx
_pyUModbus_la_CXXFLAGS = $(UNISET_CFLAGS) $(UNISET_EXT_CFLAGS) $(PYTHON_CFLAGS) _pyUModbus_la_CXXFLAGS = $(UNISET_CFLAGS) $(UNISET_EXT_CFLAGS) $(PYTHON_CFLAGS)
_pyUModbus_la_LDFLAGS = -module -avoid-version _pyUModbus_la_LDFLAGS = -module -avoid-version
_pyUModbus_la_LIBADD = $(UNISET_LIBS) $(UNISET_EXT_LIBS) $(PYTHON_LIBS) _pyUModbus_la_LIBADD = $(UNISET_LIBS) $(UNISET_EXT_LIBS) $(PYTHON_LIBS)
...@@ -29,7 +29,7 @@ UModbus_wrap.cxx: UInterface.i UModbus.h ...@@ -29,7 +29,7 @@ UModbus_wrap.cxx: UInterface.i UModbus.h
swig -python -c++ -classic UModbus.i swig -python -c++ -classic UModbus.i
_pyUExceptions_la_SOURCES = UExceptions_wrap.cxx _pyUExceptions_la_SOURCES = UExceptions_wrap.cxx
_pyUExceptions_la_CXXFLAGS = $(UNISET_CFLAGS) $(UNISET_EXT_CFLAGS) $(PYTHON_CFLAGS) _pyUExceptions_la_CXXFLAGS = $(UNISET_CFLAGS) $(UNISET_EXT_CFLAGS) $(PYTHON_CFLAGS)
_pyUExceptions_la_LDFLAGS = -module -avoid-version _pyUExceptions_la_LDFLAGS = -module -avoid-version
_pyUExceptions_la_LIBADD = $(UNISET_LIBS) $(UNISET_EXT_LIBS) $(PYTHON_LIBS) _pyUExceptions_la_LIBADD = $(UNISET_LIBS) $(UNISET_EXT_LIBS) $(PYTHON_LIBS)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "UInterface.h" #include "UInterface.h"
#include "Configuration.h" #include "Configuration.h"
#include "UniSetTypes.h" #include "UniSetTypes.h"
#include "pyUInterface.h" #include "PyUInterface.h"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
using namespace std; using namespace std;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
......
...@@ -71,10 +71,6 @@ long UConnector::getValue( long id, long node )throw(UException) ...@@ -71,10 +71,6 @@ long UConnector::getValue( long id, long node )throw(UException)
{ {
return ui->getValue(id,node); return ui->getValue(id,node);
} }
catch( UException& ex )
{
throw;
}
catch( UniSetTypes::Exception& ex ) catch( UniSetTypes::Exception& ex )
{ {
throw UException(ex.what()); throw UException(ex.what());
...@@ -100,10 +96,6 @@ void UConnector::setValue( long id, long val, long node )throw(UException) ...@@ -100,10 +96,6 @@ void UConnector::setValue( long id, long val, long node )throw(UException)
{ {
ui->setValue(id,val,node); ui->setValue(id,val,node);
} }
catch( UException& ex )
{
throw;
}
catch( UniSetTypes::Exception& ex ) catch( UniSetTypes::Exception& ex )
{ {
throw UException(ex.what()); throw UException(ex.what());
......
...@@ -14,7 +14,7 @@ class UConnector ...@@ -14,7 +14,7 @@ class UConnector
UConnector( UTypes::Params* p, const char* xmlfile )throw(UException); UConnector( UTypes::Params* p, const char* xmlfile )throw(UException);
~UConnector(); ~UConnector();
inline const char* getUIType(){ return "uniset"; } inline const char* getUIType(){ return "uniset"; }
const char* getConfFileName(); const char* getConfFileName();
long getValue( long id, long node )throw(UException); long getValue( long id, long node )throw(UException);
......
...@@ -24,7 +24,7 @@ struct UTimeOut: ...@@ -24,7 +24,7 @@ struct UTimeOut:
struct USysError: struct USysError:
public UException public UException
{ {
USysError():UException("UTimeOut"){} USysError():UException("USysError"){}
USysError( const std::string& e ):UException(e){} USysError( const std::string& e ):UException(e){}
~USysError(){} ~USysError(){}
}; };
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
%module pyUniSet %module pyUniSet
%{ %{
#include "pyUInterface.h" #include "PyUInterface.h"
%} %}
/* Для генерации классов и констант в Питоне */ /* Для генерации классов и констант в Питоне */
%include "pyUInterface.h" %include "PyUInterface.h"
%include "UTypes.h" %include "UTypes.h"
%include "UExceptions.h" %include "UExceptions.h"
...@@ -3055,7 +3055,7 @@ namespace swig { ...@@ -3055,7 +3055,7 @@ namespace swig {
} }
#include "pyUInterface.h" #include "PyUInterface.h"
SWIGINTERN swig_type_info* SWIGINTERN swig_type_info*
......
...@@ -3,13 +3,9 @@ ...@@ -3,13 +3,9 @@
import sys import sys
sys.path.append('./.libs/') #sys.path.append('../lib/')
sys.path.append('../../lib/pyUniSet/.libs/')
sys.path.append('../../lib/pyUniSet/')
#from pyUniSet import * from uniset import *
from pyUConnector import *
from pyUExceptions import *
if __name__ == "__main__": if __name__ == "__main__":
...@@ -45,9 +41,14 @@ if __name__ == "__main__": ...@@ -45,9 +41,14 @@ if __name__ == "__main__":
print "(1)setValue exception: " + str(e.getError()) print "(1)setValue exception: " + str(e.getError())
try: try:
print "(1)getValue: %d=%d" % ( 3, uc1.getValue(3,DefaultID) ) print "(2)getValue: %d=%d" % ( 3, uc1.getValue(3,DefaultID) )
except UException, e: except UException, e:
print "(1)getValue exception: " + str(e.getError()) print "(2)getValue exception: " + str(e.getError())
try:
print "(3)getValue: %d=%d" % ( 100, uc1.getValue(100,DefaultID) )
except UException, e:
print "(3)getValue exception: " + str(e.getError())
except UException, e: except UException, e:
print "(testUI): catch exception: " + str(e.getError()) print "(testUI): catch exception: " + str(e.getError())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment