class SlipTcpClient(SlipClient): def __init__(self, address, port, database, ostream, response_timeout=3.0, database_response_timeout=10.0): self.socket = SocketDevice('uart', '0', address, port) self.socket.start() super(SlipTcpClient, self).__init__(database, ostream, response_timeout, database_response_timeout) def write(self, buf): self.socket.write(buf) def read(self, size): buf = self.socket.read(size) if not buf: print('Connection closed.', file=self.ostream) _thread.interrupt_main() raise ClientClosedError() return buf
class Serial(object): """A stub communicating over a TCP socket instead of a serial port. """ def __init__(self, device, *args, **kwargs): del args del kwargs self.device = SocketDevice('uart', device) self.device.start() def close(self): self.device.stop() def write(self, buf): self.device.write(buf) def read(self, length=1): return self.device.read(length)