mirror of https://github.com/Desuuuu/klipper.git
serialhdl: Eventually timeout connect attempt
If the serial connection has not been successful after 2.5 minutes then report an error. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
ebb375fee9
commit
d98bbc772c
|
@ -614,8 +614,11 @@ class MCU:
|
||||||
and not os.path.exists(self._serialport)):
|
and not os.path.exists(self._serialport)):
|
||||||
# Try toggling usb power
|
# Try toggling usb power
|
||||||
self._check_restart("enable power")
|
self._check_restart("enable power")
|
||||||
self._serial.connect()
|
try:
|
||||||
self._clocksync.connect(self._serial)
|
self._serial.connect()
|
||||||
|
self._clocksync.connect(self._serial)
|
||||||
|
except serialhdl.error as e:
|
||||||
|
raise error(str(e))
|
||||||
msgparser = self._serial.get_msgparser()
|
msgparser = self._serial.get_msgparser()
|
||||||
name = self._name
|
name = self._name
|
||||||
log_info = [
|
log_info = [
|
||||||
|
|
|
@ -67,8 +67,11 @@ class SerialReader:
|
||||||
def connect(self):
|
def connect(self):
|
||||||
# Initial connection
|
# Initial connection
|
||||||
logging.info("Starting serial connect")
|
logging.info("Starting serial connect")
|
||||||
|
start_time = self.reactor.monotonic()
|
||||||
while 1:
|
while 1:
|
||||||
starttime = self.reactor.monotonic()
|
connect_time = self.reactor.monotonic()
|
||||||
|
if connect_time > start_time + 150.:
|
||||||
|
raise error("Unable to connect")
|
||||||
try:
|
try:
|
||||||
if self.baud:
|
if self.baud:
|
||||||
self.ser = serial.Serial(
|
self.ser = serial.Serial(
|
||||||
|
@ -77,7 +80,7 @@ class SerialReader:
|
||||||
self.ser = open(self.serialport, 'rb+')
|
self.ser = open(self.serialport, 'rb+')
|
||||||
except (OSError, IOError, serial.SerialException) as e:
|
except (OSError, IOError, serial.SerialException) as e:
|
||||||
logging.warn("Unable to open port: %s", e)
|
logging.warn("Unable to open port: %s", e)
|
||||||
self.reactor.pause(starttime + 5.)
|
self.reactor.pause(connect_time + 5.)
|
||||||
continue
|
continue
|
||||||
if self.baud:
|
if self.baud:
|
||||||
stk500v2_leave(self.ser, self.reactor)
|
stk500v2_leave(self.ser, self.reactor)
|
||||||
|
@ -87,7 +90,7 @@ class SerialReader:
|
||||||
self.background_thread.start()
|
self.background_thread.start()
|
||||||
# Obtain and load the data dictionary from the firmware
|
# Obtain and load the data dictionary from the firmware
|
||||||
try:
|
try:
|
||||||
identify_data = self._get_identify_data(starttime + 5.)
|
identify_data = self._get_identify_data(connect_time + 5.)
|
||||||
except error as e:
|
except error as e:
|
||||||
logging.exception("Timeout on serial connect")
|
logging.exception("Timeout on serial connect")
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
Loading…
Reference in New Issue