From 44b03f486cfd2a80c64452bdf4096af11e325026 Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Tue, 23 Feb 2016 12:13:32 -0800 Subject: [PATCH] Firmware upload utility improvements. --- bin/ad2-firmwareupload | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/bin/ad2-firmwareupload b/bin/ad2-firmwareupload index e68e44d..9b171df 100755 --- a/bin/ad2-firmwareupload +++ b/bin/ad2-firmwareupload @@ -56,18 +56,28 @@ def main(): print "Flashing device: {0} - {2} baud\r\nFirmware: {1}".format(device, firmware, baudrate) - if ':' in device: - hostname, port = device.split(':') - dev = alarmdecoder.devices.SocketDevice(interface=(hostname, int(port))) - dev.open(no_reader_thread=True) - else: - dev = alarmdecoder.devices.SerialDevice(interface=device) - dev.open(baudrate=baudrate, no_reader_thread=True) + dev = None + try: + if ':' in device: + hostname, port = device.split(':') + dev = alarmdecoder.devices.SocketDevice(interface=(hostname, int(port))) + dev.open(no_reader_thread=True) + else: + dev = alarmdecoder.devices.SerialDevice(interface=device) + dev.open(baudrate=baudrate, no_reader_thread=True) - time.sleep(3) - alarmdecoder.util.Firmware.upload(dev, firmware, handle_firmware, debug=debug) + time.sleep(3) + alarmdecoder.util.Firmware.upload(dev, firmware, handle_firmware, debug=debug) - dev.close() + except alarmdecoder.util.NoDeviceError, ex: + print "Error: Could not find device: {0}".format(ex) + except alarmdecoder.util.UploadError, ex: + print "Error: Error uploading firmware: {0}".format(ex) + except Exception, ex: + print "Error: {0}".format(ex) + finally: + if dev is not None: + dev.close() if __name__ == "__main__": main()