Improve shutdown time of Controller Handler.

This commit is contained in:
Matthew Stratford 2022-03-12 16:00:05 +00:00
parent 02137a3948
commit 1e77f337b1

View file

@ -68,7 +68,9 @@ class MattchBox(Controller):
if port:
# connect to serial port
self.ser = serial.serial_for_url(port, do_not_open=True)
if self.ser:
self.ser.baudrate = 2400
self.ser.timeout = 0.1 # Speed up waiting for a byte.
try:
self.ser.open()
self.logger.log.info("Connected to serial port {}".format(port))
@ -88,6 +90,7 @@ class MattchBox(Controller):
self.ser and self.ser.is_open and self.port
): # If self.port is changing (via state_handler), we should stop.
try:
if self.ser.in_waiting > 0:
line = int.from_bytes(
self.ser.read(1), "big"
) # Endianness doesn't matter for 1 byte.