Commit 30141c1d authored by Milan Prica's avatar Milan Prica

As currently deployed at FERMI.

parents
NAME = slushutter-srv
MAIN = SLUshutter.py
DIRNAME = $(NAME:-srv=)
MODNAME = $(MAIN:.py=)
PY_FILES += $(wildcard src/*.py)
default: bin ${PY_FILES}
@cp ${PY_FILES} bin/${DIRNAME}
@echo "#!/usr/bin/env python\nimport sys\nsys.path.append(sys.path[0]+'/${DIRNAME}')\nfrom ${MODNAME} import main\nif __name__ == '__main__':\n main()\n" > bin/${NAME}
@chmod +x bin/${NAME} bin/${DIRNAME}/${MAIN}
bin:
@test -d $@ || mkdir -p $@/${DIRNAME}
clean:
@rm -fr bin/ src/*~
.PHONY: clean
# SLU shutter
slushutter-srv -> SLUshutter.py
PyTango device with two commands: open(), close() that controls
the USER SEED LASER switch and reports the corresponding state
(OPEN/CLOSE).
Needed to allow the reuse of valves-like graphic inteface.
Has one device property:
Device name of the Tango device that actually controls the shutter.
(e.g. 'ldm/daq/executer_exp_daq' for LDM BL).
#!/usr/bin/env python
# "$Name: $";
# "$Header: /home/cvsadm/cvsroot/fermi/servers/slushutter/SLUshutter.py,v 1.1.1.1 2014-03-13 10:57:43 milan Exp $";
#=============================================================================
#
# file : SLUshutter.py
#
# description : Very simple Tango device with two basic commands:
# open and close and the corresponding state.
#
# project : TANGO Device Server
#
# $Author: milan $ Elettra SCI.COMP.GROUP.
#
# $Revision: 1.1.1.1 $
#
#=============================================================================
#
import sys
import PyTango
#==================================================================
# Device States Description:
# DevState.INIT: Initializing device
# DevState.OPEN : Shutter open
# DevState.CLOSE : Shutter closed
# DevState.FAULT : Connection lost
#==================================================================
class SLUshutter(PyTango.Device_4Impl):
#------------------------------------------------------------------
# Device constructor
#------------------------------------------------------------------
def __init__(self,cl, name):
print 'In Device constructor'
PyTango.Device_4Impl.__init__(self,cl,name)
SLUshutter.init_device(self)
#------------------------------------------------------------------
# Device destructor
#------------------------------------------------------------------
def delete_device(self):
print "[Device delete_device method] for device",self.get_name()
#------------------------------------------------------------------
# Device initialization
#------------------------------------------------------------------
def init_device(self):
# print "In ", self.get_name(), "::init_device()"
self.set_state(PyTango.DevState.INIT)
self.status_string = "Initializing device..."
self.get_device_properties(self.get_device_class())
try:
self.shutter_proxy = PyTango.DeviceProxy(self.ShutterDevice)
if self.shutter_proxy.SLU_shutter_opened:
self.set_state(PyTango.DevState.OPEN)
else:
self.set_state(PyTango.DevState.CLOSE)
except PyTango.DevFailed:
print 'proxy failed'
self.set_state(PyTango.DevState.FAULT)
#------------------------------------------------------------------
# Always excuted hook method
#------------------------------------------------------------------
def always_executed_hook(self):
# print "In ", self.get_name(), "::always_executed_hook()"
try:
if self.shutter_proxy.SLU_shutter_opened:
self.set_state(PyTango.DevState.OPEN)
else:
self.set_state(PyTango.DevState.CLOSE)
except PyTango.DevFailed:
print 'proxy failed'
self.set_state(PyTango.DevState.FAULT)
#==================================================================
#
# SLUshutter command methods
#
#==================================================================
#------------------------------------------------------------------
# Open command:
#
# Description: open shutter
#------------------------------------------------------------------
def Open(self):
print "In ", self.get_name(), "::Open()"
try:
self.shutter_proxy.SLU_shutter_opened = True
except PyTango.DevFailed:
print 'proxy failed'
self.set_state(PyTango.DevState.FAULT)
#------------------------------------------------------------------
# Close command:
#
# Description: open shutter
#------------------------------------------------------------------
def Close(self):
print "In ", self.get_name(), "::Close()"
try:
self.shutter_proxy.SLU_shutter_opened = False
except PyTango.DevFailed:
print 'proxy failed'
self.set_state(PyTango.DevState.FAULT)
#==================================================================
#
# SLUshutterClass class definition
#
#==================================================================
class SLUshutterClass(PyTango.DeviceClass):
# Class Properties
class_property_list = {
}
# Device Properties
device_property_list = {
'ShutterDevice':
[PyTango.DevString,
'TangoDevice that controls SLU shutter.',
'ldm/daq/executer_exp_daq'],
}
# Command definitions
cmd_list = {
'Open':
[[PyTango.DevVoid, 'Open shutter'],
[PyTango.DevVoid]],
'Close':
[[PyTango.DevVoid, 'Close shutter'],
[PyTango.DevVoid]],
}
#------------------------------------------------------------------
# SLUshutterClass Constructor
#------------------------------------------------------------------
def __init__(self, name):
print 'In SLUshutterClass constructor'
PyTango.DeviceClass.__init__(self, name)
self.set_type(name);
#==================================================================
#
# SLUshutter class main method
#
#==================================================================
if __name__ == '__main__':
try:
py = PyTango.Util(sys.argv)
py.add_TgClass(SLUshutterClass,SLUshutter,'SLUshutter')
U = PyTango.Util.instance()
U.server_init()
U.server_run()
except PyTango.DevFailed,e:
print '-------> Received a DevFailed exception:',e
except Exception,e:
print '-------> An unforeseen exception occured....',e
\ No newline at end of file
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