♻ Improve timeout handling during auto connect
That should work around issues when the printer takes longer to boot up and respond properly. See #3627
This commit is contained in:
1 parent
27191f5202
commit
d2a23c3dc7
5 files changed
+43
-21
No files matched your search
@@ -145,7 +145,8 @@ def getSettings():
|
||||
"baudrateOptions": connectionOptions["baudrates"],
|
||||
"autoconnect": s.getBoolean(["serial", "autoconnect"]),
|
||||
"timeoutConnection": s.getFloat(["serial", "timeout", "connection"]),
|
||||
"timeoutDetection": s.getFloat(["serial", "timeout", "detection"]),
|
||||
"timeoutDetectionFirst": s.getFloat(["serial", "timeout", "detectionFirst"]),
|
||||
"timeoutDetectionConsecutive": s.getFloat(["serial", "timeout", "detectionConsecutive"]),
|
||||
"timeoutCommunication": s.getFloat(["serial", "timeout", "communication"]),
|
||||
"timeoutCommunicationBusy": s.getFloat(["serial", "timeout", "communicationBusy"]),
|
||||
"timeoutTemperature": s.getFloat(["serial", "timeout", "temperature"]),
|
||||
@@ -442,8 +443,9 @@ def _saveSettings(data):
|
||||
if "baudrate" in data["serial"]: s.setInt(["serial", "baudrate"], data["serial"]["baudrate"])
|
||||
if "exclusive" in data["serial"]: s.setBoolean(["serial", "exclusive"], data["serial"]["exclusive"])
|
||||
if "timeoutConnection" in data["serial"]: s.setFloat(["serial", "timeout", "connection"], data["serial"]["timeoutConnection"], min=1.0)
|
||||
if "timeoutDetection" in data["serial"]: s.setFloat(["serial", "timeout", "detection"], data["serial"]["timeoutDetection"], min=1.0)
|
||||
if "timeoutCommunication" in data["serial"]: s.setFloat(["serial", "timeout", "communication"], data["serial"]["timeoutCommunication"], min=1.0)
|
||||
if "timeoutDetectionFirst" in data["serial"]: s.setFloat(["serial", "timeout", "detectionFirst"], data["serial"]["timeoutDetectionFirst"], min=1.0)
|
||||
if "timeoutDetectionConsecutive" in data["serial"]: s.setFloat(["serial", "timeout", "detectionConsecutive"], data["serial"]["timeoutDetectionConsecutive"], min=1.0)
|
||||
if "timeoutCommunication" in data["serial"]: s.setFloat(["serial", "timeout", "communication"], data["serial"]["timeoutCommunicationFirst"], min=1.0)
|
||||
if "timeoutCommunicationBusy" in data["serial"]: s.setFloat(["serial", "timeout", "communicationBusy"], data["serial"]["timeoutCommunicationBusy"], min=1.0)
|
||||
if "timeoutTemperature" in data["serial"]: s.setFloat(["serial", "timeout", "temperature"], data["serial"]["timeoutTemperature"], min=1.0)
|
||||
if "timeoutTemperatureTargetSet" in data["serial"]: s.setFloat(["serial", "timeout", "temperatureTargetSet"], data["serial"]["timeoutTemperatureTargetSet"], min=1.0)
|
||||
|
||||
@@ -98,7 +98,8 @@ default_settings = {
|
||||
"autoconnect": False,
|
||||
"log": False,
|
||||
"timeout": {
|
||||
"detection": 1,
|
||||
"detectionFirst": 10,
|
||||
"detectionConsecutive": 2,
|
||||
"connection": 10,
|
||||
"communication": 30,
|
||||
"communicationBusy": 3,
|
||||
|
||||
@@ -158,7 +158,8 @@ $(function() {
|
||||
self.serial_baudrateOptions = ko.observableArray([]);
|
||||
self.serial_autoconnect = ko.observable(undefined);
|
||||
self.serial_timeoutConnection = ko.observable(undefined);
|
||||
self.serial_timeoutDetection = ko.observable(undefined);
|
||||
self.serial_timeoutDetectionFirst = ko.observable(undefined);
|
||||
self.serial_timeoutDetectionConsecutive = ko.observable(undefined);
|
||||
self.serial_timeoutCommunication = ko.observable(undefined);
|
||||
self.serial_timeoutCommunicationBusy = ko.observable(undefined);
|
||||
self.serial_timeoutTemperature = ko.observable(undefined);
|
||||
|
||||
@@ -173,14 +173,25 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group" title="{{ _('Time after which to consider an auto detection attempt to have failed if no successful connection is detected')|edq }}">
|
||||
<label class="control-label" for="settings-serialTimeoutDetection">{{ _('Autodetection timeout') }}</label>
|
||||
<div class="control-group" title="{{ _('Time after which to consider the auto detection handshake attempt to have failed if no successful connection is detected')|edq }}">
|
||||
<label class="control-label" for="settings-serialTimeoutDetectionFirst">{{ _('Autodetection timeout') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="number" step="any" min="1" class="input-mini text-right" data-bind="value: serial_timeoutDetection" id="settings-serialTimeoutDetection">
|
||||
<input type="number" step="any" min="1" class="input-mini text-right" data-bind="value: serial_timeoutDetectionFirst" id="settings-serialTimeoutDetectionFirst">
|
||||
<span class="add-on">s</span>
|
||||
</div>
|
||||
<span class="help-inline">{{ _('First handshake attempt')}}</span>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="number" step="any" min="1" class="input-mini text-right" data-bind="value: serial_timeoutDetectionConsecutive" id="settings-serialTimeoutDetectionConsecutive">
|
||||
<span class="add-on">s</span>
|
||||
</div>
|
||||
<span class="help-inline">{{ _('Consecutive handshake attempts')}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group" title="{{ _('Time after which to consider further auto detection attempts to have failed if no successful connection is detected')|edq }}">
|
||||
<label class="control-label" for="settings-serialTimeoutDetectionConsecutive">{{ _('Autodetection timeout (further tries)') }}</label>
|
||||
</div>
|
||||
<div class="control-group" title="{{ _('Time after which to consider a position query on pause or cancel to have failed')|edq }}">
|
||||
<label class="control-label" for="settings-serialTimeoutPositionLogWait">{{ _('Position query timeout') }}</label>
|
||||
|
||||
+20
-13
@@ -1672,15 +1672,14 @@ class MachineCom(object):
|
||||
return
|
||||
try_hello = not settings().getBoolean(["serial", "waitForStartOnConnect"])
|
||||
self._changeState(self.STATE_CONNECTING)
|
||||
self._timeout = self._ok_timeout = self._get_new_communication_timeout()
|
||||
else:
|
||||
self._changeState(self.STATE_DETECT_SERIAL)
|
||||
self._perform_detection_step(init=True)
|
||||
|
||||
# Start monitoring the serial port
|
||||
self._log("Connected to: %s, starting monitor" % self._serial)
|
||||
|
||||
#Start monitoring the serial port.
|
||||
self._timeout = self._ok_timeout = self._get_new_communication_timeout()
|
||||
|
||||
startSeen = False
|
||||
supportRepetierTargetTemp = settings().getBoolean(["serial", "repetierTargetTemp"])
|
||||
supportWait = settings().getBoolean(["serial", "supportWait"])
|
||||
@@ -1839,7 +1838,8 @@ class MachineCom(object):
|
||||
and (not self.job_on_hold or self._resendActive)
|
||||
and not self._long_running_command
|
||||
and not self._heating and now >= self._ok_timeout)) \
|
||||
and (not self._blockWhileDwelling or not self._dwelling_until or now > self._dwelling_until):
|
||||
and (not self._blockWhileDwelling or not self._dwelling_until or now > self._dwelling_until)\
|
||||
and not self._state in (self.STATE_DETECT_SERIAL,):
|
||||
# We have two timeout variants:
|
||||
#
|
||||
# Variant 1: No line at all received within the communication timeout. This can always happen.
|
||||
@@ -2218,7 +2218,7 @@ class MachineCom(object):
|
||||
|
||||
### Serial detection
|
||||
if self._state == self.STATE_DETECT_SERIAL:
|
||||
if line == '' or monotonic_time() > self._timeout:
|
||||
if line == '' or monotonic_time() > self._ok_timeout:
|
||||
self._perform_detection_step()
|
||||
elif 'start' in line or line.startswith('ok'):
|
||||
self._onConnected()
|
||||
@@ -2377,7 +2377,6 @@ class MachineCom(object):
|
||||
self._logger.info("Serial detection: {}".format(message))
|
||||
|
||||
if init:
|
||||
timeout = settings().getFloat(["serial", "timeout", "connection"])
|
||||
port = self._port
|
||||
baudrate = self._baudrate
|
||||
|
||||
@@ -2396,27 +2395,26 @@ class MachineCom(object):
|
||||
baudrate_candidates = baudrateList([115200, 250000])
|
||||
|
||||
self._detection_candidates = [(p, b) for p in port_candidates for b in baudrate_candidates]
|
||||
self._detection_retry = self.DETECTION_RETRIES
|
||||
|
||||
log("Performing autodetection with {} " \
|
||||
"port/baudrate candidates: {}".format(len(self._detection_candidates),
|
||||
", ".join(map(lambda x: "{}@{}".format(x[0], x[1]),
|
||||
self._detection_candidates))))
|
||||
|
||||
else:
|
||||
timeout = settings().getFloat(["serial", "timeout", "detection"])
|
||||
|
||||
def attempt_handshake():
|
||||
timeout = self._get_communication_timeout_interval()
|
||||
if self._serial.timeout != timeout:
|
||||
self._serial.timeout = timeout
|
||||
self._timeout = monotonic_time() + timeout
|
||||
self._timeout = self._ok_timeout = monotonic_time() + timeout
|
||||
|
||||
log("Handshake attempt #{}".format(self._detection_retry + 1))
|
||||
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", })
|
||||
|
||||
while len(self._detection_candidates) > 0:
|
||||
while len(self._detection_candidates) > 0 or self._detection_retry < self.DETECTION_RETRIES:
|
||||
if self._detection_retry < self.DETECTION_RETRIES:
|
||||
attempt_handshake()
|
||||
return
|
||||
@@ -2425,6 +2423,7 @@ class MachineCom(object):
|
||||
(p, b) = self._detection_candidates.pop(0)
|
||||
|
||||
try:
|
||||
log("Trying port {}, baudrate {}".format(p, b))
|
||||
if self._serial is None or self._serial.port != p:
|
||||
if not self._open_serial(p, b, trigger_errors=False):
|
||||
log("Could not open port {}, baudrate {}, skipping".format(p, b))
|
||||
@@ -2432,7 +2431,6 @@ class MachineCom(object):
|
||||
else:
|
||||
self._serial.baudrate = b
|
||||
|
||||
log("Trying port {}, baudrate {}".format(p, b))
|
||||
self._detection_retry = 0
|
||||
|
||||
attempt_handshake()
|
||||
@@ -2654,6 +2652,15 @@ class MachineCom(object):
|
||||
return interval
|
||||
|
||||
def _get_communication_timeout_interval(self):
|
||||
# special rules during serial detection
|
||||
if self._state in (self.STATE_DETECT_SERIAL,):
|
||||
if self._detection_retry == 0:
|
||||
# first try
|
||||
return self._timeout_intervals.get("detectionFirst", 10.0)
|
||||
else:
|
||||
# consecutive tries
|
||||
return self._timeout_intervals.get("detectionConsecutive", 2.0)
|
||||
|
||||
# communication timeout
|
||||
if self._busy_protocol_support:
|
||||
comm_timeout = self._timeout_intervals.get("communicationBusy", 2.0)
|
||||
|
||||
Reference in new issue
Block a user