openpilot v0.9.6 release
date: 2024-02-21T23:02:42 master commit: 0b4d08fab8e35a264bc7383e878538f8083c33e5
This commit is contained in:
35
panda/python/serial.py
Normal file
35
panda/python/serial.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# 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._baudrate = baud
|
||||
self.panda.set_uart_baud(self.port, baud)
|
||||
self.buf = b""
|
||||
|
||||
def read(self, l=1):
|
||||
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):
|
||||
return self.panda.serial_write(self.port, dat)
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user