diff --git a/meshtastic/serial_interface.py b/meshtastic/serial_interface.py index 7133b392..39f26482 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -46,12 +46,7 @@ def __init__(self, devPath: Optional[str]=None, debugOut=None, noProto: bool=Fal logging.debug(f"Connecting to {self.devPath}") - # 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 + # first we need to set the HUPCL 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: @@ -60,14 +55,10 @@ def __init__(self, devPath: Optional[str]=None, debugOut=None, noProto: bool=Fal termios.tcsetattr(f, termios.TCSAFLUSH, attrs) f.close() time.sleep(0.1) - else: - self.stream.rts = 0 - self.stream.dtr = 0 - - # 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)