|
@@ -22,6 +22,7 @@ class AutoDetectBaudJob(Job):
|
|
def run(self):
|
|
def run(self):
|
|
Logger.log("d", "Auto detect baud rate started.")
|
|
Logger.log("d", "Auto detect baud rate started.")
|
|
timeout = 3
|
|
timeout = 3
|
|
|
|
+ tries = 2
|
|
|
|
|
|
programmer = Stk500v2()
|
|
programmer = Stk500v2()
|
|
serial = None
|
|
serial = None
|
|
@@ -31,36 +32,38 @@ class AutoDetectBaudJob(Job):
|
|
except:
|
|
except:
|
|
programmer.close()
|
|
programmer.close()
|
|
|
|
|
|
- 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))
|
|
|
|
|
|
+ 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 serial is None:
|
|
|
|
- try:
|
|
|
|
- serial = Serial(str(self._serial_port), baud_rate, timeout = timeout, writeTimeout = timeout)
|
|
|
|
- except SerialException as e:
|
|
|
|
- Logger.logException("w", "Unable to create serial")
|
|
|
|
- continue
|
|
|
|
- else:
|
|
|
|
- # We already have a serial connection, just change the baud rate.
|
|
|
|
- try:
|
|
|
|
- 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
|
|
|
|
- successful_responses = 0
|
|
|
|
|
|
+ if serial is None:
|
|
|
|
+ try:
|
|
|
|
+ serial = Serial(str(self._serial_port), baud_rate, timeout = timeout, writeTimeout = timeout)
|
|
|
|
+ except SerialException as e:
|
|
|
|
+ Logger.logException("w", "Unable to create serial")
|
|
|
|
+ continue
|
|
|
|
+ else:
|
|
|
|
+ # We already have a serial connection, just change the baud rate.
|
|
|
|
+ try:
|
|
|
|
+ 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
|
|
|
|
+ successful_responses = 0
|
|
|
|
|
|
- serial.write(b"\n") # Ensure we clear out previous responses
|
|
|
|
- serial.write(b"M105\n")
|
|
|
|
|
|
+ serial.write(b"\n") # Ensure we clear out previous responses
|
|
|
|
+ serial.write(b"M105\n")
|
|
|
|
|
|
- timeout_time = time() + timeout
|
|
|
|
|
|
+ timeout_time = time() + timeout
|
|
|
|
|
|
- while timeout_time > time():
|
|
|
|
- line = serial.readline()
|
|
|
|
- if b"ok T:" in line:
|
|
|
|
- successful_responses += 1
|
|
|
|
- if successful_responses >= 3:
|
|
|
|
- self.setResult(baud_rate)
|
|
|
|
- return
|
|
|
|
|
|
+ while timeout_time > time():
|
|
|
|
+ line = serial.readline()
|
|
|
|
+ if b"ok T:" in line:
|
|
|
|
+ successful_responses += 1
|
|
|
|
+ if successful_responses >= 3:
|
|
|
|
+ self.setResult(baud_rate)
|
|
|
|
+ return
|
|
|
|
|
|
- serial.write(b"M105\n")
|
|
|
|
|
|
+ serial.write(b"M105\n")
|
|
|
|
+ sleep(15) # Give the printer some time to init and try again.
|
|
self.setResult(None) # Unable to detect the correct baudrate.
|
|
self.setResult(None) # Unable to detect the correct baudrate.
|