From da416fcd20dd59a11721a92f0d64c62ee4b95aa2 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 14 Oct 2025 07:54:37 -0700 Subject: [PATCH] refactor flush The double flush() is not the root cause; the real issue is that code is trying to use the serial port after it has been closed. The error occurs both in close() (during flush()) and later in _writeBytes() (during write()), indicating the port is closed or invalid at those times. --- meshtastic/serial_interface.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/meshtastic/serial_interface.py b/meshtastic/serial_interface.py index ef4eeaf..e3b7400 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -89,10 +89,12 @@ class SerialInterface(StreamInterface): try: self.stream.flush() time.sleep(0.1) - # FIXME: why are there these two flushes with 100ms sleeps? This shouldn't be necessary - self.stream.flush() - time.sleep(0.1) except Exception as e: logger.debug(f"Exception during flush: {e}") + try: + self.stream.close() + except Exception as e: + logger.debug(f"Exception during close: {e}") + self.stream = None logger.debug("Closing Serial stream") StreamInterface.close(self)