Script execution
This commit is contained in:
@@ -15,23 +15,28 @@ class RobotTCP(TcpDevice):
|
||||
self.header = None
|
||||
self.trailer = "\n"
|
||||
self.msg_id = 0
|
||||
|
||||
def call(self, msg):
|
||||
|
||||
def _sendReceive(self, id, msg = ""):
|
||||
tx = self.header if (self.header != None) else ""
|
||||
id = "%03d" % self.msg_id
|
||||
self.msg_id = (self.msg_id+1)%1000
|
||||
tx = tx + id + " " + msg
|
||||
if (len(tx)>127):
|
||||
raise Exception("Exceeded maximum message size")
|
||||
self.getLogger().finer("TX = " + str(tx))
|
||||
if (self.trailer != None): tx = tx + self.trailer
|
||||
rx = self.sendReceive(tx, None, self.trailer , 0, self.timeout, self.retries).strip()
|
||||
rx = self.sendReceive(tx, None, self.trailer , 0, self.timeout, self.retries)
|
||||
self.getLogger().finer("RX = " + str(rx))
|
||||
if rx[:3] != id:
|
||||
if rx[:3] != id:
|
||||
raise Exception("Received invalid message id: " + str(rx[:3]) + " - expecting:" + id )
|
||||
if len(rx)<4:
|
||||
raise Exception("Invalid message size: " + str(len(rx)) )
|
||||
if rx[3] == "*":
|
||||
raise Exception(rx[4:])
|
||||
return rx[4:]
|
||||
return rx[4:-1]
|
||||
|
||||
def call(self, msg):
|
||||
id = "%03d" % self.msg_id
|
||||
self.msg_id = (self.msg_id+1)%1000
|
||||
return self._sendReceive(id, msg)
|
||||
|
||||
def execute(self, command, *argv):
|
||||
msg = str(command)
|
||||
@@ -43,12 +48,7 @@ class RobotTCP(TcpDevice):
|
||||
return ret;
|
||||
|
||||
def get_event(self):
|
||||
id = "EVT"
|
||||
rx = self.sendReceive(id + " ", None, self.trailer , 0, self.timeout, self.retries).strip()
|
||||
if rx[:3] != id:
|
||||
raise Exception("Received invalid message id: " + str(rx[:3]) + " - expecting:" + id )
|
||||
if len(rx) < 5: return None
|
||||
return rx[4:]
|
||||
return self._sendReceive("EVT")
|
||||
|
||||
def mount(self, puck, sample):
|
||||
return self.execute('Mount', puck, sample)
|
||||
|
||||
Reference in New Issue
Block a user