🐛 Set closed state even if not yet open

And also ensure we only attempt serial auto detect if we are still in
the correct state for it.

Closes #3653
This commit is contained in:
Gina Häußge committed 2020-07-27 15:59:47 +02:00
1 parent 0188745d05
commit 0cfc08748b
1 file changed
+17 -6
+17 -6
View File
@@ -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"):