From 5246e2ccb46931a07ace169fa2eda02afeeb3cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Jul 2020 11:31:37 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20for=20some=20bugs=20in=20a?= =?UTF-8?q?uto=20detection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Probably related to #3653 --- src/octoprint/util/comm.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index d159fec24..6547e53a8 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2408,19 +2408,27 @@ class MachineCom(object): self._detection_candidates)))) def attempt_handshake(): - timeout = self._get_communication_timeout_interval() - if self._serial.timeout != timeout: - self._serial.timeout = timeout - self._timeout = self._ok_timeout = monotonic_time() + timeout - - log("Handshake attempt #{} with timeout {}s".format(self._detection_retry + 1, timeout)) - self._detection_retry += 1 - self._do_send_without_checksum(b"", log=False) # new line to reset things - self.sayHello(tags={"trigger:detection", }) + timeout = self._get_communication_timeout_interval() + + log("Handshake attempt #{} with timeout {}s".format(self._detection_retry, timeout)) + try: + if self._serial.timeout != timeout: + self._serial.timeout = timeout + self._timeout = self._ok_timeout = monotonic_time() + timeout + except Exception: + self._log("Unexpected error while setting timeout {}: {}".format(timeout, get_exception_string())) + self._logger.exception("Unexpected error while setting timeout {}".format(timeout)) + else: + self._do_send_without_checksum(b"", log=False) # new line to reset things + self.sayHello(tags={"trigger:detection", }) while len(self._detection_candidates) > 0 or self._detection_retry < self.DETECTION_RETRIES: if self._detection_retry < self.DETECTION_RETRIES: + if self._serial is None: + self._detection_retry = self.DETECTION_RETRIES + continue + attempt_handshake() return