serial-device/transport/serial/__init__.py
2023-10-01 22:41:21 +03:00

28 lines
605 B
Python

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()