Closedown

This commit is contained in:
gac-S_Changer
2017-02-28 09:03:30 +01:00
parent 59c9ac12d0
commit 5c92439130

View File

@@ -1,3 +1,5 @@
import threading
class RobotTCP(TcpDevice, Stoppable):
def __init__(self, name, server, timeout = 1000, retries = 1):
TcpDevice.__init__(self, name, server)
@@ -15,6 +17,7 @@ class RobotTCP(TcpDevice, Stoppable):
self.empty = None
self.working_mode = None
self.status = None
self.lock = threading.Lock()
def _sendReceive(self, msg_id, msg = "", timeout = None):
tx = self.header if (self.header != None) else ""
@@ -36,9 +39,13 @@ class RobotTCP(TcpDevice, Stoppable):
return rx[4:]
def call(self, msg, timeout = None):
id = "%03d" % self.msg_id
self.msg_id = (self.msg_id+1)%1000
return self._sendReceive(id, msg, timeout)
self.lock.aquire()
try:
id = "%03d" % self.msg_id
self.msg_id = (self.msg_id+1)%1000
return self._sendReceive(id, msg, timeout)
finally:
self.lock.release()
def execute(self, command, *args, **kwargs):
timeout = None if (kwargs is None) or (not kwargs.has_key("timeout")) else kwargs["timeout"]