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)
|
|
|
|
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
|
|
|
|
2020-06-01 16:49:26 +08:00
|
|
|
def read(self, l=1): # noqa: E741
|
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
|