From 37c977cea6ca904345eb20827d8be2f7ed0a76f6 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 30 Oct 2015 13:45:19 +0100 Subject: [PATCH] Properly end firmware update procedure and catch errors during firmware update Contributes to CURA-274 --- plugins/USBPrinting/PrinterConnection.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/USBPrinting/PrinterConnection.py b/plugins/USBPrinting/PrinterConnection.py index c78dcf1697..341fe425b1 100644 --- a/plugins/USBPrinting/PrinterConnection.py +++ b/plugins/USBPrinting/PrinterConnection.py @@ -45,7 +45,7 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter): self._connect_thread.daemon = True self._end_stop_thread = threading.Thread(target = self._pollEndStop) - self._end_stop_thread.deamon = True + self._end_stop_thread.daemon = True self._poll_endstop = -1 # Printer is connected @@ -64,7 +64,8 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter): self._listen_thread.daemon = True self._update_firmware_thread = threading.Thread(target= self._updateFirmware) - self._update_firmware_thread.deamon = True + self._update_firmware_thread.daemon = True + self.firmwareUpdateComplete.connect(self._onFirmwareUpdateComplete) self._heatup_wait_start_time = time.time() @@ -197,6 +198,8 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter): ## Private fuction (threaded) that actually uploads the firmware. def _updateFirmware(self): + self.setProgress(0, 100) + if self._is_connecting or self._is_connected: self.close() hex_file = intelHex.readHex(self._firmware_file_name) @@ -207,7 +210,11 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter): programmer = stk500v2.Stk500v2() programmer.progressCallback = self.setProgress - programmer.connect(self._serial_port) + + try: + programmer.connect(self._serial_port) + except Exception: + pass time.sleep(1) # Give programmer some time to connect. Might need more in some cases, but this worked in all tested cases. @@ -336,8 +343,8 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter): self._connect_thread = threading.Thread(target=self._connect) self._connect_thread.daemon = True + self.setIsConnected(False) if self._serial is not None: - self.setIsConnected(False) try: self._listen_thread.join() except: @@ -622,6 +629,6 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter): def _onFirmwareUpdateComplete(self): self._update_firmware_thread.join() self._update_firmware_thread = threading.Thread(target= self._updateFirmware) - self._update_firmware_thread.deamon = True + self._update_firmware_thread.daemon = True self.connect()