1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
import PyTango
import socket
import MotorController
nb_call = 0
class IcePapController(MotorController.MotorController):
MaxDevice = 4
def __init__(self, inst, props):
print "PYTHON -> IcePapController ctor for instance", inst
MotorController.MotorController.__init__(self, inst, props)
self.nb_call = 0
self.socket_connected = False
self.db = PyTango.Database()
self.ct_name = "IcePapController/" + self.inst_name
#
# Get controller properties
#
prop_list = ['host', 'port', 'timeout']
prop = self.db.get_property(self.ct_name, prop_list)
if len(prop["host"]) != 0:
self.host = prop["host"][0]
else:
print "Property host not defined for controller", self.ct_name
self.host = "nada"
if len(prop["port"]) != 0:
self.port = int(prop["port"][0])
else:
print "Property port not defined for controller", self.ct_name
self.port = 0
if len(prop["timeout"]) != 0:
self.timeout = int(prop["timeout"][0])
else:
print "Property timeout not defined for controller", self.ct_name
self.timeout = 3
#
# Connect to the icepap
#
print "PYTHON -> IcePap on", self.host, " and port", self.port, " with timeout = ", self.timeout
global nb_call
if nb_call <= 1:
nb_call = nb_call + 1
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(self.timeout)
self.sock.connect((self.host, self.port))
self.socket_connected = True
print "PYTHON -> Connected to", self.host, " on port", self.port
#
# Check that the Icepap is OK
#
# ans = self.IceWriteRead("?ID")
def AddDevice(self, axis):
print "PYTHON -> IcePapController/", self.inst_name, ": In AddDevice method for axis", axis
# raise RuntimeError,"Hola la la"
def DeleteDevice(self, axis):
print "PYTHON -> IcePapController/", self.inst_name, ": In DeleteDevice method for axis", axis
def StateOne(self, axis):
print "PYTHON -> IcePapController/", self.inst_name, ": In StateOne method for axis", axis
tup = (PyTango.DevState.ON, 0)
return tup
def PreReadAll(self):
print "PYTHON -> IcePapController/", self.inst_name, ": In PreReadAll method"
def PreReadOne(self, axis):
print "PYTHON -> IcePapController/", self.inst_name, ": In PreReadOne method for axis", axis
def ReadAll(self):
print "PYTHON -> IcePapController/", self.inst_name, ": In ReadAll method"
def ReadOne(self, axis):
print "PYTHON -> IcePapController/", self.inst_name, ": In ReadOne method for axis", axis
return 123
def PreStartAll(self):
print "PYTHON -> IcePapController/", self.inst_name, ": In PreStartAll method"
def PreStartOne(self, axis, pos):
print "PYTHON -> IcePapController/", self.inst_name, ": In PreStartOne method for axis", axis, " with pos", pos
return True
def StartOne(self, axis, pos):
print "PYTHON -> IcePapController/", self.inst_name, ": In StartOne method for axis", axis, " with pos", pos
def StartAll(self):
print "PYTHON -> IcePapController/", self.inst_name, ": In StartAll method"
def SetPar(self, axis, name, value):
print "PYTHON -> IcePapController/", self.inst_name, ": In SetPar method for axis", axis, " name=", name, " value=", value
def GetPar(self, axis, name):
print "PYTHON -> IcePapController/", self.inst_name, ": In GetPar method for axis", axis, " name=", name
return 12.34
def IceWrite(self, data):
data = data + "\n"
byteSent = self.sock.send(data)
print "PYTHON -> Sent", byteSent, "bytes to icepap"
def IceWriteRead(self, data):
self.IceWrite(data)
byteReceived = self.sock.recv(1024)
print "PYTHON -> Icepap answered:", byteReceived
return byteReceived
def IceResetFifo(self):
self.IceWrite("fiforst")
def IceCheckError(self, ice_answer):
if (ice_answer.find("ERROR") != -1):
new_ans = self.IceWriteRead("?ERR 1")
print "Error from IcePap =", new_ans
def __del__(self):
print "PYTHON -> IcePapController/", self.inst_name, ": Aarrrrrg, I am dying"
#
# Reset IcePap FIFO
#
if (self.socket_connected):
print "PYTHON -> Closing connection"
self.IceResetFifo()
self.sock.close()
if __name__ == "__main__":
obj = IcePapController('test')
# obj.AddDevice(2)
# obj.DeleteDevice(2)
|