Commit 94dddc14 authored by Pavel Vainerman's avatar Pavel Vainerman

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

parent 180b7d9b
...@@ -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,10 +19,10 @@ def to_int(s): ...@@ -19,10 +19,10 @@ 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 s.__class__.__name__ == "float": if isinstance(s,float):
return int(s) 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':
......
#!/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 *
...@@ -4,12 +4,12 @@ python_SCRIPTS = pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py ...@@ -4,12 +4,12 @@ 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
......
...@@ -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;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -38,7 +38,7 @@ long pyUInterface::getValue( long id )throw(UException) ...@@ -38,7 +38,7 @@ long pyUInterface::getValue( long id )throw(UException)
{ {
if( !UniSetTypes::conf || !ui ) if( !UniSetTypes::conf || !ui )
throw USysError(); throw USysError();
UniversalIO::IOType t = UniSetTypes::conf->getIOType(id); UniversalIO::IOType t = UniSetTypes::conf->getIOType(id);
try try
{ {
...@@ -50,7 +50,7 @@ long pyUInterface::getValue( long id )throw(UException) ...@@ -50,7 +50,7 @@ long pyUInterface::getValue( long id )throw(UException)
case UniversalIO::AO: case UniversalIO::AO:
return ui->getValue(id); return ui->getValue(id);
break; break;
default: default:
{ {
ostringstream e; ostringstream e;
...@@ -71,7 +71,7 @@ long pyUInterface::getValue( long id )throw(UException) ...@@ -71,7 +71,7 @@ long pyUInterface::getValue( long id )throw(UException)
{ {
throw UException("(getValue): catch..."); throw UException("(getValue): catch...");
} }
throw UException("(getValue): unknown error"); throw UException("(getValue): unknown error");
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -79,7 +79,7 @@ void pyUInterface::setValue( long id, long val )throw(UException) ...@@ -79,7 +79,7 @@ void pyUInterface::setValue( long id, long val )throw(UException)
{ {
if( !UniSetTypes::conf || !ui ) if( !UniSetTypes::conf || !ui )
throw USysError(); throw USysError();
UniversalIO::IOType t = UniSetTypes::conf->getIOType(id); UniversalIO::IOType t = UniSetTypes::conf->getIOType(id);
try try
{ {
...@@ -91,7 +91,7 @@ void pyUInterface::setValue( long id, long val )throw(UException) ...@@ -91,7 +91,7 @@ void pyUInterface::setValue( long id, long val )throw(UException)
case UniversalIO::AO: case UniversalIO::AO:
ui->setValue(id,val); ui->setValue(id,val);
break; break;
default: default:
{ {
ostringstream e; ostringstream e;
...@@ -118,7 +118,7 @@ long pyUInterface::getSensorID( const char* name ) ...@@ -118,7 +118,7 @@ long pyUInterface::getSensorID( const char* name )
{ {
if( UniSetTypes::conf ) if( UniSetTypes::conf )
return UniSetTypes::conf->getSensorID(name); return UniSetTypes::conf->getSensorID(name);
return -1; return -1;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -126,7 +126,7 @@ const char* pyUInterface::getName( long id ) ...@@ -126,7 +126,7 @@ const char* pyUInterface::getName( long id )
{ {
if( UniSetTypes::conf ) if( UniSetTypes::conf )
return UniSetTypes::conf->oind->getMapName(id).c_str(); return UniSetTypes::conf->oind->getMapName(id).c_str();
return ""; return "";
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -134,7 +134,7 @@ const char* pyUInterface::getShortName( long id ) ...@@ -134,7 +134,7 @@ const char* pyUInterface::getShortName( long id )
{ {
if( UniSetTypes::conf ) if( UniSetTypes::conf )
return ORepHelpers::getShortName(UniSetTypes::conf->oind->getMapName(id)).c_str(); return ORepHelpers::getShortName(UniSetTypes::conf->oind->getMapName(id)).c_str();
return ""; return "";
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -142,7 +142,7 @@ const char* pyUInterface::getTextName( long id ) ...@@ -142,7 +142,7 @@ const char* pyUInterface::getTextName( long id )
{ {
if( UniSetTypes::conf ) if( UniSetTypes::conf )
return UniSetTypes::conf->oind->getTextName(id).c_str(); return UniSetTypes::conf->oind->getTextName(id).c_str();
return ""; return "";
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -150,7 +150,7 @@ const char* pyUInterface::getConfFileName() ...@@ -150,7 +150,7 @@ const char* pyUInterface::getConfFileName()
{ {
if( UniSetTypes::conf ) if( UniSetTypes::conf )
return UniSetTypes::conf->getConfFileName().c_str(); return UniSetTypes::conf->getConfFileName().c_str();
return ""; return "";
} }
......
#ifndef pyUInterface_H_ #ifndef pyUInterface_H_
#define pyUInterface_H_ #define pyUInterface_H_
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <string> #include <string>
#include "UTypes.h" #include "UTypes.h"
#include "UExceptions.h" #include "UExceptions.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
namespace pyUInterface namespace pyUInterface
{ {
void uniset_init_params( UTypes::Params* p, const char* xmlfile )throw(UException); void uniset_init_params( UTypes::Params* p, const char* xmlfile )throw(UException);
...@@ -15,13 +15,13 @@ namespace pyUInterface ...@@ -15,13 +15,13 @@ namespace pyUInterface
void setValue( long id, long val )throw(UException); void setValue( long id, long val )throw(UException);
long getSensorID( const char* ); long getSensorID( const char* );
const char* getShortName( long id ); const char* getShortName( long id );
const char* getName( long id ); const char* getName( long id );
const char* getTextName( long id ); const char* getTextName( long id );
const char* getConfFileName(); const char* getConfFileName();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#endif #endif
......
...@@ -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