Tune timeouts in serial

pull/246/head
Holger Müller 2020-07-12 21:33:19 +02:00
rodzic 2244f57779
commit 9a73e8ba81
1 zmienionych plików z 7 dodań i 0 usunięć

Wyświetl plik

@ -23,15 +23,21 @@ import serial
logger = logging.getLogger(__name__)
def drain_serial(serial_port: serial.Serial):
"""drain up to 64k outstanding data in the serial incoming buffer"""
# logger.debug("Draining: %s", serial_port)
timeout = serial_port.timeout
serial_port.timeout = 0.05
for _ in range(512):
cnt = len(serial_port.read(128))
if not cnt:
serial_port.timeout = timeout
return
serial_port.timeout = timeout
logger.warning("unable to drain all data")
class Interface(serial.Serial):
def __init__(self, interface_type: str, comment, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -40,6 +46,7 @@ class Interface(serial.Serial):
self.comment = comment
self.port = None
self.baudrate = 115200
self.timeout = 0.05
self.lock = Lock()
def __str__(self):