Skip to content

Commit

Permalink
Scripts renamed, setup.py ready
Browse files Browse the repository at this point in the history
  • Loading branch information
sergi_rubio committed Sep 13, 2016
1 parent b6d94ad commit 7952f0c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 38 deletions.
40 changes: 20 additions & 20 deletions SimulatorDS-lite.p → SimulatorDS-lite.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# "$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
#
# $Author: [email protected]
#
# $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
#
Expand Down Expand Up @@ -52,7 +52,7 @@
from fandango.dynamic import DynamicDS,DynamicDSClass,DynamicAttribute

#==================================================================
# PySignalSimulator Class Description:
# SimulatorDS Class Description:
#
# <p>This device requires <a href="http://www.tango-controls.org/Documents/tools/fandango/fandango">Fandango module<a> to be available in the PYTHONPATH.</p>
# <p>
Expand Down Expand Up @@ -90,7 +90,7 @@
#==================================================================


class PySignalSimulator(DynamicDS): #PyTango.Device_4Impl):
class SimulatorDS(DynamicDS): #PyTango.Device_4Impl):

#--------- Add you global variables here --------------------------

Expand All @@ -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 = {}
Expand All @@ -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
Expand All @@ -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()"
Expand All @@ -144,7 +144,7 @@ def always_executed_hook(self):

#==================================================================
#
# PySignalSimulator read/write attribute methods
# SimulatorDS read/write attribute methods
#
#==================================================================
#------------------------------------------------------------------
Expand All @@ -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 = {
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 7 additions & 10 deletions SimulatorDS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
53 changes: 49 additions & 4 deletions bin/SimulatorDS
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
#!/bin/sh
#!/bin/bash

. alba_blissrc
# This script is a variant from TangoScripts/tango_pyds
# [email protected], 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
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
Expand Down

0 comments on commit 7952f0c

Please sign in to comment.