In the following example, the virtual motor is a dummy device. The piece of code can be used as a template. The class name VM and the function names are fixed.
In addition it is demonstrated how a device property is accessed.
#!/bin/env python
import PyTango, HasyUtils
import inspect
import HasyUtils
class VM:
#
# init_device
#
def __init__( self):
self.ResultSim = None
self.PositionSim = None
self.Position = 0
self.UnitLimitMin = -100
self.UnitLimitMax = 100
#
# demo for accessing the VmCode property
#
self.parent = inspect.currentframe().f_back.f_locals['self']
self.parentProxy = PyTango.DeviceProxy( self.parent.get_name())
VmCode = HasyUtils.getDeviceProperty( self.parent.get_name(), "VmCode")[0]
#print "VmCode", VmCode
return
#
# dev_state
#
def dev_state( self):
argout = PyTango.DevState.ON
return argout
#
# Position
#
def read_Position( self):
return self.Position
def write_Position( self, argin):
if( argin < self.UnitLimitMin or
argin > self.UnitLimitMax):
PyTango.Except.throw_exception(
"vm_dummy",
"requested position outside limits %g %g " % (self.UnitLimitMin, self.UnitLimitMax),
"VmExecutor")
self.Position = argin
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
#
# PositionSim
#
def read_PositionSim( self):
if self.PositionSim is None:
PyTango.Except.throw_exception( "vm_dummy", "PositionSim is undefined", "VmExecutor")
return self.PositionSim
def write_PositionSim( self, argin):
self.PositionSim = argin
self.ResultSim = []
self.ResultSim.append( "x: %g " % argin)
def read_ResultSim( self):
if self.ResultSim is None:
PyTango.Except.throw_exception( "vm_dummy", "ResultSim is undefined", "VmExecutor")
return self.ResultSim
def StopMove( self):
return 1
def Calibrate(self, argin):
return 1