From dea5f788a271626b7e8a95027c968b48f278eed2 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Thu, 13 Nov 2025 12:07:32 -0700 Subject: [PATCH 1/3] Revert "Add more exception logging, fix some additional stream read/write issues" This reverts commit f15a0bdc0bd3d847b24f852f35efc6541f4a5d42. --- meshtastic/stream_interface.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/meshtastic/stream_interface.py b/meshtastic/stream_interface.py index dc4109e..82b6ab5 100644 --- a/meshtastic/stream_interface.py +++ b/meshtastic/stream_interface.py @@ -104,7 +104,7 @@ class StreamInterface(MeshInterface): def _writeBytes(self, b: bytes) -> None: """Write an array of bytes to our stream and flush""" - if self.stream and self.stream is not None and getattr(self.stream, "is_open", False): # ignore writes when stream is closed + if self.stream: # ignore writes when stream is closed self.stream.write(b) self.stream.flush() # win11 might need a bit more time, too @@ -116,7 +116,7 @@ class StreamInterface(MeshInterface): def _readBytes(self, length) -> Optional[bytes]: """Read an array of bytes from our stream""" - if self.stream and self.stream is not None and getattr(self.stream, "is_open", False): + if self.stream: return self.stream.read(length) else: return None @@ -226,12 +226,10 @@ class StreamInterface(MeshInterface): logger.error( f"Unexpected OSError, terminating meshtastic reader... {ex}" ) - traceback.print_exc() except Exception as ex: logger.error( f"Unexpected exception, terminating meshtastic reader... {ex}" ) - traceback.print_exc() finally: logger.debug("reader is exiting") self._disconnected() From 096fec95c8327c91a21ce7a598ea7c909dc5a6f1 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Thu, 13 Nov 2025 12:07:48 -0700 Subject: [PATCH 2/3] Revert "Wrap double-close in a try-catch. Slightly ugly but oh well." This reverts commit dbc0101a7a4c97efbdd9efab9178d8e24f03a5b2. --- meshtastic/stream_interface.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/meshtastic/stream_interface.py b/meshtastic/stream_interface.py index 82b6ab5..06ee28a 100644 --- a/meshtastic/stream_interface.py +++ b/meshtastic/stream_interface.py @@ -93,12 +93,9 @@ class StreamInterface(MeshInterface): logger.debug("Closing our port") # pylint: disable=E0203 - if hasattr(self, "stream") and self.stream is not None and getattr(self.stream, "is_open", False): + if not self.stream is None: # pylint: disable=E0203 - try: - self.stream.close() - except Exception as e: - logger.debug(f"Exception during close: {e}") + self.stream.close() # pylint: disable=W0201 self.stream = None From aeec5447edb5dd7d42a0f3ac75f3400fbb0361c4 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Thu, 13 Nov 2025 12:08:42 -0700 Subject: [PATCH 3/3] Revert "Merge pull request #841 from SpudGunMan/master" This reverts commit b4662251ed9f3383d8ad964b42cce395af17dfc2, reversing changes made to 2065598754f382c3f5535314460528fbcd346240. --- meshtastic/serial_interface.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/meshtastic/serial_interface.py b/meshtastic/serial_interface.py index 8d1397c..88f17de 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -94,16 +94,10 @@ class SerialInterface(StreamInterface): def close(self) -> None: """Close a connection to the device""" - if hasattr(self, "stream") and self.stream and getattr(self.stream, "is_open", False): - try: - 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 + if self.stream: # Stream can be null if we were already closed + self.stream.flush() # FIXME: why are there these two flushes with 100ms sleeps? This shouldn't be necessary + time.sleep(0.1) + self.stream.flush() + time.sleep(0.1) logger.debug("Closing Serial stream") StreamInterface.close(self)