mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
CURA-5396 added timeout options for auto detecting baud rate over USB serial
This commit is contained in:
parent
49e49bfa58
commit
b2b9de7960
1 changed files with 20 additions and 4 deletions
|
@ -22,6 +22,10 @@ class AutoDetectBaudJob(Job):
|
|||
def run(self):
|
||||
Logger.log("d", "Auto detect baud rate started.")
|
||||
timeout = 3
|
||||
wait_response_timeouts = [3, 15, 30]
|
||||
wait_bootloader_times = [1.5, 5, 15]
|
||||
write_timeout = 3
|
||||
read_timeout = 3
|
||||
tries = 2
|
||||
|
||||
programmer = Stk500v2()
|
||||
|
@ -34,11 +38,20 @@ class AutoDetectBaudJob(Job):
|
|||
|
||||
for retry in range(tries):
|
||||
for baud_rate in self._all_baud_rates:
|
||||
Logger.log("d", "Checking {serial} if baud rate {baud_rate} works".format(serial= self._serial_port, baud_rate = baud_rate))
|
||||
if retry < len(wait_response_timeouts):
|
||||
wait_response_timeout = wait_response_timeouts[retry]
|
||||
else:
|
||||
wait_response_timeout = wait_response_timeouts[-1]
|
||||
if retry < len(wait_bootloader_times):
|
||||
wait_bootloader = wait_bootloader_times[retry]
|
||||
else:
|
||||
wait_bootloader = wait_bootloader_times[-1]
|
||||
Logger.log("d", "Checking {serial} if baud rate {baud_rate} works. Retry nr: {retry}. Wait timeout: {timeout}".format(
|
||||
serial = self._serial_port, baud_rate = baud_rate, retry = retry, timeout = wait_response_timeout))
|
||||
|
||||
if serial is None:
|
||||
try:
|
||||
serial = Serial(str(self._serial_port), baud_rate, timeout = timeout, writeTimeout = timeout)
|
||||
serial = Serial(str(self._serial_port), baud_rate, timeout = read_timeout, writeTimeout = write_timeout)
|
||||
except SerialException as e:
|
||||
Logger.logException("w", "Unable to create serial")
|
||||
continue
|
||||
|
@ -48,13 +61,14 @@ class AutoDetectBaudJob(Job):
|
|||
serial.baudrate = baud_rate
|
||||
except:
|
||||
continue
|
||||
sleep(1.5) # Ensure that we are not talking to the boot loader. 1.5 seconds seems to be the magic number
|
||||
sleep(wait_bootloader) # Ensure that we are not talking to the boot loader. 1.5 seconds seems to be the magic number
|
||||
successful_responses = 0
|
||||
|
||||
serial.write(b"\n") # Ensure we clear out previous responses
|
||||
serial.write(b"M105\n")
|
||||
|
||||
timeout_time = time() + timeout
|
||||
start_timeout_time = time()
|
||||
timeout_time = time() + wait_response_timeout
|
||||
|
||||
while timeout_time > time():
|
||||
line = serial.readline()
|
||||
|
@ -62,6 +76,8 @@ class AutoDetectBaudJob(Job):
|
|||
successful_responses += 1
|
||||
if successful_responses >= 3:
|
||||
self.setResult(baud_rate)
|
||||
Logger.log("d", "Detected baud rate {baud_rate} on serial {serial} on retry {retry} with after {time_elapsed:0.2f} seconds.".format(
|
||||
serial = self._serial_port, baud_rate = baud_rate, retry = retry, time_elapsed = time() - start_timeout_time))
|
||||
return
|
||||
|
||||
serial.write(b"M105\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue