From 85d212ba97f75aade3f8536e6bad303a0a4548b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 2 Jul 2019 16:35:57 +0200 Subject: [PATCH] =?UTF-8?q?=E2=98=94=20More=20resilience=20against=20garba?= =?UTF-8?q?ge=20on=20the=20line=20on=20initial=20connect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We'll now send the hello command twice, and a third time if we run into a timeout during initial connect. Closes #3206 --- src/octoprint/util/comm.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 9e2fa5436..c5b2ae8c4 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -441,6 +441,7 @@ class MachineCom(object): self._max_write_passes = settings().getInt(["serial", "maxWritePasses"]) self._hello_command = settings().get(["serial", "helloCommand"]) + self._hello_sent = 0 self._trigger_ok_for_m29 = settings().getBoolean(["serial", "triggerOkForM29"]) self._hello_command = settings().get(["serial", "helloCommand"]) @@ -1508,6 +1509,7 @@ class MachineCom(object): self.sendCommand(self._hello_command, force=True, tags=tags | {"trigger:comm.say_hello",}) self._clear_to_send.set() + self._hello_sent += 1 def resetLineNumbers(self, number=0, part_of_job=False, tags=None): if not self.isOperational(): @@ -1623,6 +1625,10 @@ class MachineCom(object): if try_hello: self.sayHello() + # we send a second one right away because sometimes there's garbage on the line on first connect + # that can kill oks + self.sayHello() + while self._monitoring_active: try: line = self._readline() @@ -2150,8 +2156,12 @@ class MachineCom(object): self._handle_ok() self._onConnected() elif monotonic_time() > self._timeout: - self._log("There was a timeout while trying to connect to the printer") - self.close(wait=False) + if try_hello and self._hello_sent < 3: + self._log("No answer from the printer within the connection timeout, trying another hello") + self.sayHello() + else: + self._log("There was a timeout while trying to connect to the printer") + self.close(wait=False) ### Operational (idle or busy) elif self._state in (self.STATE_OPERATIONAL,