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))