From 46203fd43c47baebc88bc10bdaf054044a1aa634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Jul 2020 15:33:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20auto=20detect=20with=20aut?= =?UTF-8?q?o=20port=20and=20set=20baudrate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3627 --- src/octoprint/util/comm.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index e24d5c327..dd4277ea1 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2405,17 +2405,20 @@ class MachineCom(object): else: timeout = settings().getFloat(["serial", "timeout", "detection"]) + def attempt_handshake(): + if self._serial.timeout != timeout: + self._serial.timeout = timeout + self._timeout = monotonic_time() + timeout + + log("Handshake attempt #{}".format(self._detection_retry + 1)) + + self._detection_retry += 1 + self._do_send_without_checksum(b"", log=False) # new line to reset things + self.sayHello(tags={"trigger:detection", }) + while len(self._detection_candidates) > 0: if self._detection_retry < self.DETECTION_RETRIES: - if self._serial.timeout != timeout: - self._serial.timeout = timeout - self._timeout = monotonic_time() + timeout - - log("Handshake attempt #{}".format(self._detection_retry + 1)) - - self._detection_retry += 1 - self._do_send_without_checksum(b"", log=False) # new line to reset things - self.sayHello(tags={"trigger:detection", }) + attempt_handshake() return else: @@ -2429,13 +2432,12 @@ class MachineCom(object): else: self._serial.baudrate = b - if self._serial.timeout != timeout: - self._serial.timeout = timeout - self._timeout = monotonic_time() + timeout - log("Trying port {}, baudrate {}".format(p, b)) self._detection_retry = 0 + attempt_handshake() + return + except Exception: self._log("Unexpected error while setting baudrate {}: {}".format(b, get_exception_string())) self._logger.exception("Unexpected error while setting baudrate {}".format(b))