diff --git a/SimulatorDS-lite.p b/SimulatorDS-lite.py similarity index 86% rename from SimulatorDS-lite.p rename to SimulatorDS-lite.py index ed862f02..53963582 100644 --- a/SimulatorDS-lite.p +++ b/SimulatorDS-lite.py @@ -1,14 +1,14 @@ # "$Name: $"; -# "$Header: /cvsroot/tango-ds/Simulators/PySignalSimulator/PySignalSimulator.py,v 1.4 2008/11/21 11:51:44 sergi_rubio Exp $"; +# "$Header: /cvsroot/tango-ds/Simulators/SimulatorDS/SimulatorDS.py,v 1.4 2008/11/21 11:51:44 sergi_rubio Exp $"; #============================================================================= # -# file : PySignalSimulator.py +# file : SimulatorDS.py # -# description : Python source for the PySignalSimulator and its commands. +# description : Python source for the SimulatorDS and its commands. # The class is derived from Device. It represents the # CORBA servant object which will be accessed from the # network. All commands which can be executed on the -# PySignalSimulator are implemented in this file. +# SimulatorDS are implemented in this file. # # project : TANGO Device Server # @@ -16,7 +16,7 @@ # # $Revision: 1.4 $ # -# $Log: PySignalSimulator.py,v $ +# $Log: SimulatorDS.py,v $ # Revision 1.4 2008/11/21 11:51:44 sergi_rubio # Adapted_to_fandango.dynamic.DynamicDS_template # @@ -52,7 +52,7 @@ from fandango.dynamic import DynamicDS,DynamicDSClass,DynamicAttribute #================================================================== -# PySignalSimulator Class Description: +# SimulatorDS Class Description: # #
This device requires Fandango module to be available in the PYTHONPATH.
#@@ -90,7 +90,7 @@ #================================================================== -class PySignalSimulator(DynamicDS): #PyTango.Device_4Impl): +class SimulatorDS(DynamicDS): #PyTango.Device_4Impl): #--------- Add you global variables here -------------------------- @@ -99,7 +99,7 @@ class PySignalSimulator(DynamicDS): #PyTango.Device_4Impl): #------------------------------------------------------------------ def __init__(self,cl, name): #PyTango.Device_4Impl.__init__(self,cl,name) - print 'IN PYSIGNALSIMULATOR.__INIT__' + print 'IN SimulatorDS.__INIT__' ##Loading special methods to be available in formulas _locals = {} @@ -113,7 +113,7 @@ def __init__(self,cl, name): except: print 'Unable to import custom Signals module' DynamicDS.__init__(self,cl,name,_locals=_locals,useDynStates=True) - PySignalSimulator.init_device(self) + SimulatorDS.init_device(self) #------------------------------------------------------------------ # Device destructor @@ -130,7 +130,7 @@ def init_device(self): self.setLogLevel('DEBUG') self.set_state(PyTango.DevState.ON) #self.get_device_properties(self.get_device_class()) #Default values of properties already initialized by DynamicDS.__init__() - #print 'PySignalSimulator Property values are:\n'+'\n'.join('\t%s:\t%s'%(k,getattr(self,k)) for k in DynamicDSClass.device_property_list) + #print 'SimulatorDS Property values are:\n'+'\n'.join('\t%s:\t%s'%(k,getattr(self,k)) for k in DynamicDSClass.device_property_list) self.get_DynDS_properties() if self.DynamicStates: self.set_state(PyTango.DevState.UNKNOWN) print "Out of ", self.get_name(), "::init_device()" @@ -144,7 +144,7 @@ def always_executed_hook(self): #================================================================== # -# PySignalSimulator read/write attribute methods +# SimulatorDS read/write attribute methods # #================================================================== #------------------------------------------------------------------ @@ -156,16 +156,16 @@ def read_attr_hardware(self,data): #================================================================== # -# PySignalSimulator command methods +# SimulatorDS command methods # #================================================================== #================================================================== # -# PySignalSimulatorClass class definition +# SimulatorDSClass class definition # #================================================================== -class PySignalSimulatorClass(DynamicDSClass): +class SimulatorDSClass(DynamicDSClass): # Class Properties class_property_list = { @@ -196,23 +196,23 @@ class PySignalSimulatorClass(DynamicDSClass): #------------------------------------------------------------------ -# PySignalSimulatorClass Constructor +# SimulatorDSClass Constructor #------------------------------------------------------------------ def __init__(self, name): PyTango.DeviceClass.__init__(self, name) self.set_type(name); - print "In PySignalSimulatorClass constructor" + print "In SimulatorDSClass constructor" #================================================================== # -# PySignalSimulator class main method +# SimulatorDS class main method # #================================================================== if __name__ == '__main__': try: - #py = PyTango.Util(sys.argv) #Rewritten because name of file doesn't match servers name - py = PyTango.Util(['PySignalSimulator',[a for a in sys.argv if not a.startswith('-')][-1]]) - py.add_TgClass(PySignalSimulatorClass,PySignalSimulator,'PySignalSimulator') + #py = PyTango.Util(sys.argv) #Rewritten because name of file doesnt match servers name + py = PyTango.Util(['SimulatorDS',[a for a in sys.argv if not a.startswith('-')][-1]]) + py.add_TgClass(SimulatorDSClass,SimulatorDS,'SimulatorDS') U = PyTango.Util.instance() U.server_init() U.server_run() diff --git a/SimulatorDS.py b/SimulatorDS.py index 70b75feb..941dfc75 100644 --- a/SimulatorDS.py +++ b/SimulatorDS.py @@ -119,7 +119,7 @@ def get_module_dict(module,ks=None): #================================================================== -class SimulatorDS(PyTango.Device_4Impl): +class SimulatorDS(DynamicDS): #--------- Add you global variables here -------------------------- LIBS = [math,random,Signals] @@ -199,7 +199,7 @@ def read_attr_hardware(self,data): # SimulatorDSClass class definition # #================================================================== -class SimulatorDSClass(PyTango.DeviceClass): +class SimulatorDSClass(DynamicDSClass): # Class Properties class_property_list = { @@ -255,16 +255,16 @@ def __init__(self, name): # #================================================================== -class PySignalSimulator(SimulatorDS): pass -class PySignalSimulatorClass(SimulatorDSClass): pass +#class PySignalSimulator(SimulatorDS): pass +#class PySignalSimulatorClass(SimulatorDSClass): pass + +#SimulatorDS,SimulatorDSClass = FullTangoInheritance('SimulatorDS',SimulatorDS,SimulatorDSClass,DynamicDS,DynamicDSClass,ForceDevImpl=True) def main(args=None): try: py = PyTango.Util(args or sys.argv) - # Adding all commands/properties from fandango.DynamicDS - SimulatorDS,SimulatorDSClass = FullTangoInheritance('SimulatorDS',SimulatorDS,SimulatorDSClass,DynamicDS,DynamicDSClass,ForceDevImpl=True) py.add_TgClass(SimulatorDSClass,SimulatorDS,'SimulatorDS') - py.add_TgClass(PySignalSimulatorClass,PySignalSimulator,'PySignalSimulator') + #py.add_TgClass(PySignalSimulatorClass,PySignalSimulator,'PySignalSimulator') U = PyTango.Util.instance() fandango.dynamic.CreateDynamicCommands(SimulatorDS,SimulatorDSClass) @@ -278,6 +278,3 @@ def main(args=None): if __name__ == '__main__': main() -else: - #Enabling subclassing - SimulatorDS,SimulatorDSClass = FullTangoInheritance('SimulatorDS',SimulatorDS,SimulatorDSClass,DynamicDS,DynamicDSClass,ForceDevImpl=True) diff --git a/bin/SimulatorDS b/bin/SimulatorDS index c80ca8c9..7d9501ca 100755 --- a/bin/SimulatorDS +++ b/bin/SimulatorDS @@ -1,6 +1,51 @@ -#!/bin/sh +#!/bin/bash -. alba_blissrc +# This script is a variant from TangoScripts/tango_pyds +# srubio@cells.es, 2016 -cd $SICILIA/ds/python/PySignalSimulator -screen -dm -S PySignalSimulator-$1 python PySignalSimulator.py $1 $2 +DS=$(basename $0) + +if [ $(echo $1 | grep "/" ) ] ; then + IFS='/' read -r DS INSTANCE <<< "$1" +else + DS=$(basename $0) + INSTANCE=$1 +fi + +DSORB=$(python -c "import PyTango;print(PyTango.Database().get_property('ORBendPoint',['${DS}/${INSTANCE}']).values()[0][0])" 2>/dev/null) +if [ "$DSORB" ] ; then + DSORB="-ORBendPoint $DSORB" +fi + +DSPATH=$(python -c "import imp;print(imp.find_module('${DS}')[1])" 2>/dev/null) + +if [ ! "$DSPATH" ] ; then + DSPATH=$(python -c "import imp;print(imp.find_module('fandango')[1])") + if [ -e "$DSPATH/device/$DS.py" ] ; then + DSPATH=$DSPATH/device + elif [ -e "$DSPATH/interface/$DS.py" ] ; then + DSPATH=$DSPATH/interface + fi +fi + +DSPATH=$(readlink -f $DSPATH) + +echo "Launching $DSPATH/$DS $INSTANCE at $DSORB" + +# TODO: if it is mandatory to be in the module path +cd ${DSPATH} + +if [ $(which screen 2>/dev/null) ] ; then + if [ ! "$(echo $* | grep attach)" ] ; then + echo "run detached" + CMD="screen -dm -S $DS-$INSTANCE " + else + CMD="screen -S $DS-$INSTANCE " + fi +else + CMD="" +fi + +CMD="${CMD} python ${DSPATH}/$DS.py $INSTANCE $2 $DSORB" +echo $CMD +$CMD diff --git a/setup.py b/setup.py index 30e318fa..32d426d1 100644 --- a/setup.py +++ b/setup.py @@ -19,11 +19,11 @@ print(__doc__) version = open('VERSION').read().strip() -scripts = ['PyPLC'] +scripts = ['bin/SimulatorDS'] license = 'GPL-3.0' package_dir = { - 'PyPLC': '.', + 'SimulatorDS': '.', } packages = package_dir.keys() @@ -34,10 +34,10 @@ packages = package_dir.keys() -setup(name = 'tangods-pyplc', +setup(name = 'tangods-simulatords', version = version, license = license, - description = 'Tango device for Modbus equipment', + description = 'Tango device for simulation and calculation', packages = packages, package_dir= package_dir, scripts = scripts,