2018-01-08 03:31:54 +08:00
|
|
|
# mimic a python serial port
|
|
|
|
class PandaSerial(object):
|
|
|
|
def __init__(self, panda, port, baud):
|
|
|
|
self.panda = panda
|
|
|
|
self.port = port
|
|
|
|
self.panda.set_uart_parity(self.port, 0)
|
2021-07-01 21:34:46 +08:00
|
|
|
self._baudrate = baud
|
2018-01-08 03:31:54 +08:00
|
|
|
self.panda.set_uart_baud(self.port, baud)
|
2019-09-28 06:22:13 +08:00
|
|
|
self.buf = b""
|
2018-01-08 03:31:54 +08:00
|
|
|
|
2023-08-15 03:52:02 +08:00
|
|
|
def read(self, l=1):
|
2018-01-08 03:31:54 +08:00
|
|
|
tt = self.panda.serial_read(self.port)
|
|
|
|
if len(tt) > 0:
|
|
|
|
self.buf += tt
|
|
|
|
ret = self.buf[0:l]
|
|
|
|
self.buf = self.buf[l:]
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def write(self, dat):
|
2019-10-16 03:05:33 +08:00
|
|
|
return self.panda.serial_write(self.port, dat)
|
2018-01-08 03:31:54 +08:00
|
|
|
|
|
|
|
def close(self):
|
|
|
|
pass
|
2021-07-01 21:34:46 +08:00
|
|
|
|
|
|
|
def flush(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
|
|
|
def baudrate(self):
|
|
|
|
return self._baudrate
|
|
|
|
|
|
|
|
@baudrate.setter
|
|
|
|
def baudrate(self, value):
|
|
|
|
self.panda.set_uart_baud(self.port, value)
|
|
|
|
self._baudrate = value
|