Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions meshtastic/serial_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@

logging.debug(f"Connecting to {self.devPath}")

# first we need to set the HUPCL so the device will not reboot based on RTS and/or DTR
# set port to None to prevent automatically opening
self.stream = serial.Serial(
port=None, baudrate=115200, exclusive=True, timeout=0.5, write_timeout=0
)

# first we need to clear HUPCL (UNIX) or clear RTS/DTR (Windows) so the device will not reboot based on RTS and/or DTR
# see https://github.com/pyserial/pyserial/issues/124
if platform.system() != "Windows":
with open(self.devPath, encoding="utf8") as f:
Expand All @@ -55,10 +60,14 @@
termios.tcsetattr(f, termios.TCSAFLUSH, attrs)
f.close()
time.sleep(0.1)
else:
self.stream.rts = 0
self.stream.dtr = 0

Check warning on line 65 in meshtastic/serial_interface.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/serial_interface.py#L64-L65

Added lines #L64 - L65 were not covered by tests

# set proper port and open now that we've worked-around RTS/DTR issues
self.stream.port = self.devPath
self.stream.open()

self.stream = serial.Serial(
self.devPath, 115200, exclusive=True, timeout=0.5, write_timeout=0
)
self.stream.flush() # type: ignore[attr-defined]
time.sleep(0.1)

Expand Down
Loading