Skip to content

Commit da416fc

Browse files
committed
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.
1 parent 93da1da commit da416fc

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

meshtastic/serial_interface.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ def close(self) -> None:
8989
try:
9090
self.stream.flush()
9191
time.sleep(0.1)
92-
# FIXME: why are there these two flushes with 100ms sleeps? This shouldn't be necessary
93-
self.stream.flush()
94-
time.sleep(0.1)
9592
except Exception as e:
9693
logger.debug(f"Exception during flush: {e}")
94+
try:
95+
self.stream.close()
96+
except Exception as e:
97+
logger.debug(f"Exception during close: {e}")
98+
self.stream = None
9799
logger.debug("Closing Serial stream")
98100
StreamInterface.close(self)

0 commit comments

Comments
 (0)