From 5ed32230f713eeb33ce953e80c0aec909995ca99 Mon Sep 17 00:00:00 2001 From: TheRikke Date: Sat, 7 Jan 2017 22:22:47 +0100 Subject: [PATCH] Fix connections to devices not based on arduino stk500v2 failed to release the serial port on timeout. --- plugins/USBPrinting/avr_isp/stk500v2.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/USBPrinting/avr_isp/stk500v2.py b/plugins/USBPrinting/avr_isp/stk500v2.py index ccbaa3de53..91bef53875 100644 --- a/plugins/USBPrinting/avr_isp/stk500v2.py +++ b/plugins/USBPrinting/avr_isp/stk500v2.py @@ -43,17 +43,20 @@ class Stk500v2(ispBase.IspBase): self.serial.flushInput() self.serial.flushOutput() - if self.sendMessage([0x10, 0xc8, 0x64, 0x19, 0x20, 0x00, 0x53, 0x03, 0xac, 0x53, 0x00, 0x00]) != [0x10, 0x00]: + try: + if self.sendMessage([0x10, 0xc8, 0x64, 0x19, 0x20, 0x00, 0x53, 0x03, 0xac, 0x53, 0x00, 0x00]) != [0x10, 0x00]: + raise ispBase.IspError("Failed to enter programming mode") + + self.sendMessage([0x06, 0x80, 0x00, 0x00, 0x00]) + if self.sendMessage([0xEE])[1] == 0x00: + self._has_checksum = True + else: + self._has_checksum = False + except ispBase.IspError: self.close() - raise ispBase.IspError("Failed to enter programming mode") - - self.sendMessage([0x06, 0x80, 0x00, 0x00, 0x00]) - if self.sendMessage([0xEE])[1] == 0x00: - self._has_checksum = True - else: - self._has_checksum = False + raise self.serial.timeout = 5 - + def close(self): if self.serial is not None: self.serial.close()