🐛 Fix auto detect with auto port and set baudrate

Closes #3627
This commit is contained in:
Gina Häußge committed 2020-07-06 15:34:14 +02:00
1 parent 38f1c74379
commit 46203fd43c
1 file changed
+15 -13
+15 -13
View File
@@ -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))