Here is an example for a VmExecutor speaking to a SECoP motor server. Notice that the following properties have to be supplied:
#!/bin/env python
"""
Properties
Motorname: drv (e.g.)
Hostname: haspp99eh (where the SECoP server runs)
Port: 5000
The corresponding entry in /online_dir/online.xml
<device>
<name>secop_drv</name>
<type>type_tango</type>
<module>motor_tango</module>
<device>p99/secop_motor/exp.01</device>
<control>tango</control>
<hostname>haspp99:10000</hostname>
</device>
"""
import socket, select
import sys, inspect, json
import PyTango, HasyUtils
class VM:
#
# init_device
#
def __init__( self):
self.parent = inspect.currentframe().f_back.f_locals['self']
try:
self.motorName = HasyUtils.getDeviceProperty( self.parent.get_name(), "Motorname")[0]
self.host = HasyUtils.getDeviceProperty( self.parent.get_name(), "Hostname")[0]
self.port = int( HasyUtils.getDeviceProperty( self.parent.get_name(), "Port")[0])
except Exception as e:
print( "secopMotor.py: expecting the properties: Motorname, Hostname, Port")
sys.exit( 255)
self.sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sckt.connect(( self.host, self.port))
self.UnitLimitMin = 0
self.UnitLimitMax = 200
return
#
#
#
def writeRead( self, msg):
#
# sends a messages, reads the reply and returns a result
#
self.sckt.send( msg + "\n")
buffer = ""
while( 1):
infds, outfds, errfds = select.select( [self.sckt], [], [], 0.12)
if len( infds) == 0:
break
buffer = buffer + self.sckt.recv( 1024)
lst = buffer.split( ' ')
com = ”.join( lst[2:]).strip()
res = json.loads( com)
argout = ""
if type( res) is list:
if type( res[0]) is list:
argout = res[0][0]
else:
argout = res[0]
return argout
#
# dev_state
#
def dev_state( self):
msg = "read %s:status" % self.motorName
res = self.writeRead( msg)
if res == 100:
argout = PyTango.DevState.ON
elif res == 300:
argout = PyTango.DevState.MOVING
elif res == 400:
argout = PyTango.DevState.ALARM
return argout
#
# Position
#
def read_Position( self):
msg = "read %s:value" % self.motorName
res = self.writeRead( msg)
return res
def write_Position( self, argin):
msg = "change %s:target %s" % ( self.motorName, repr( argin))
buffer = self.writeRead( msg)
#
# reply for a move to 33: [33.0, {"t": 1635954831.2276042}]
#
return 1
#
# UnitLimitMax
#
def read_UnitLimitMax( self):
return self.UnitLimitMax
def write_UnitLimitMax( self, argin):
self.UnitLimitMax = argin
#
# UnitLimitMin
#
def read_UnitLimitMin( self):
return self.UnitLimitMin
def write_UnitLimitMin( self, argin):
self.UnitLimitMin = argin
#
# CwLimit, CcwLimit
#
def read_CwLimit( self):
return 0
def read_CcwLimit( self):
return 0
def StopMove( self):
msg = "do %s:stop" % self.motorName
buffer = self.writeRead( msg)
return 1