def __init__(self): self.f = FilterMotor() self.fw = FilterWheelParser(self, self.f) self.f.connDev() # Pass protocol to FilterMotor.py self.f.motorProtocol = self
class FilterWheelServer(basic.LineReceiver): def __init__(self): self.f = FilterMotor() self.fw = FilterWheelParser(self, self.f) self.f.connDev() # Pass protocol to FilterMotor.py self.f.motorProtocol = self def connectionMade(self): """ If you send more than one line then the callback to start the gui will completely fail. """ self.factory.clients.append(self) def connectionLost(self, reason): self.factory.clients.remove(self) self.f.disconnDev() def lineReceived(self, line): print("received", line) d = threads.deferToThread(self.fw.parse, line) d.addCallback(self.sendData) def sendData(self, data): if data is not None: self.sendMessage(str(data)) def sendMessage(self, message): for client in self.factory.clients: client.sendLine(message)