diff --git a/script/RobotTCP.py b/script/RobotTCP.py index 4fd16e6..25a55fa 100644 --- a/script/RobotTCP.py +++ b/script/RobotTCP.py @@ -18,54 +18,25 @@ class RobotTCP(TcpDevice, Stoppable): self.working_mode = None self.status = None self.lock = threading.Lock() + def _sendReceive(self, msg_id, msg = ""): - """ - self.lock.acquire() - try: - tx = self.header if (self.header != None) else "" - tx = tx + msg_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 - start = time.time() - sending = True - while(True): - if sending: - rx = self.sendReceive(tx, None, self.trailer , 0, self.timeout, self.retries) - else: - rx = self.wa - rx=rx[:-1] #Remove 0A - self.getLogger().finer("RX = '" + str(rx) + "'") - if rx[:3] != msg_id: - if (time.time()-start) >= timeout: - raise Exception("Received invalid message id: " + str(rx[:3]) + " - expecting:" + msg_id ) - else: - if len(rx)<4: - raise Exception("Invalid message size: " + str(len(rx)) ) - if rx[3] == "*": - raise Exception(rx[4:]) - return rx[4:] - finally: - self.lock.release() - """ - tx = self.header if (self.header != None) else "" - tx = tx + msg_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 , msg_id, self.timeout, self.retries) - rx=rx[:-1] #Remove 0A - self.getLogger().finer("RX = '" + str(rx) + "'") - if rx[:3] != msg_id: - if (time.time()-start) >= timeout: - raise Exception("Received invalid message id: " + str(rx[:3]) + " - expecting:" + msg_id ) - if len(rx)<4: - raise Exception("Invalid message size: " + str(len(rx)) ) - if rx[3] == "*": - raise Exception(rx[4:]) - return rx[4:] + tx = self.header if (self.header != None) else "" + tx = tx + msg_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, msg_id, self.trailer , 0, self.timeout, self.retries) + rx=rx[:-1] #Remove 0A + self.getLogger().finer("RX = '" + str(rx) + "'") + if rx[:3] != msg_id: + if (time.time()-start) >= timeout: + raise Exception("Received invalid message id: " + str(rx[:3]) + " - expecting:" + msg_id ) + if len(rx)<4: + raise Exception("Invalid message size: " + str(len(rx)) ) + if rx[3] == "*": + raise Exception(rx[4:]) + return rx[4:] def call(self, msg): id = "%03d" % self.msg_id