2023-10-01 22:41:21 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-10-09 03:49:29 +03:00
|
|
|
def write_line(self, cmd_str):
|
2023-10-01 22:41:21 +03:00
|
|
|
self.ser.write(str.encode(cmd_str + "\n"))
|
|
|
|
return 1
|
|
|
|
|
2023-10-09 03:49:29 +03:00
|
|
|
def read_line(self):
|
2023-10-01 22:41:21 +03:00
|
|
|
buffer = self.ser.readline()
|
|
|
|
return buffer.decode('utf-8').rstrip()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self.ser.close()
|