From 0cfc08748b2e21774318d0f7ed217709d13a0b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Jul 2020 15:59:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Set=20closed=20state=20even=20if?= =?UTF-8?q?=20not=20yet=20open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And also ensure we only attempt serial auto detect if we are still in the correct state for it. Closes #3653 --- src/octoprint/util/comm.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 6547e53a8..058ab725e 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -995,15 +995,17 @@ class MachineCom(object): self._logger.exception("Error while trying to close serial port") is_error = True - # if we are printing, this will also make sure of firing PRINT_FAILED - if is_error: - self._changeState(self.STATE_CLOSED_WITH_ERROR) - else: - self._changeState(self.STATE_CLOSED) else: deactivate_monitoring_and_send_queue() + self._serial = None + # if we are printing, this will also make sure of firing PRINT_FAILED + if is_error: + self._changeState(self.STATE_CLOSED_WITH_ERROR) + else: + self._changeState(self.STATE_CLOSED) + if settings().getBoolean(["feature", "sdSupport"]): self._sdFileList = [] @@ -1682,6 +1684,10 @@ class MachineCom(object): self._changeState(self.STATE_DETECT_SERIAL) self._perform_detection_step(init=True) + if not self._state in (self.STATE_CONNECTING, self.STATE_DETECT_SERIAL): + # we got cancelled during connection, bail + return + # Start monitoring the serial port self._log("Connected to: %s, starting monitor" % self._serial) @@ -2424,6 +2430,9 @@ class MachineCom(object): self.sayHello(tags={"trigger:detection", }) while len(self._detection_candidates) > 0 or self._detection_retry < self.DETECTION_RETRIES: + if self._state not in (self.STATE_DETECT_SERIAL,): + return + if self._detection_retry < self.DETECTION_RETRIES: if self._serial is None: self._detection_retry = self.DETECTION_RETRIES @@ -2753,7 +2762,9 @@ class MachineCom(object): serial_obj.close() serial_obj.parity = serial.PARITY_NONE - serial_obj.open() + #serial_obj.open() + time.sleep(5.0) + raise OSError(22, 'The semaphore timeout period has expired.', None, 121) # Set close_exec flag on serial handle, see #3212 if hasattr(serial_obj, "fd"):