import serial from transport.base import TransportBase class Transport(TransportBase): def __init__(self, config): super().__init__(config) self.ser = serial.Serial() self.ser.port = config["tty_name"] self.ser.open() self.ser.flushInput() self.ser.flushOutput() self.addr = None def writeline(self, cmd_str): self.ser.write(str.encode(cmd_str + "\n")) return 1 def readline(self): buffer = self.ser.readline() return buffer.decode('utf-8').rstrip() def close(self): self.ser.close()