altoslib: Close serial port when AltosFlash fails to detect a target
authorKeith Packard <keithp@keithp.com>
Mon, 18 Aug 2014 03:51:36 +0000 (20:51 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 18 Aug 2014 03:51:36 +0000 (20:51 -0700)
AltosDebug.check_connection raises an exception when the link fails,
but the AltosFlash constructor didn't close the serial port in this
case, causing the serial port to appear to be busy.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosFlash.java

index bd4fb6d09d4658a6c23dd283ff94b4d38ac3c991..a8519550d98b62dd4e757243ce5f435a4d51409e 100644 (file)
@@ -345,9 +345,23 @@ public class AltosFlash extends AltosProgrammer {
                        debug = new AltosDebug(link);
                input = new FileInputStream(file);
                image = new AltosHexfile(input);
                        debug = new AltosDebug(link);
                input = new FileInputStream(file);
                image = new AltosHexfile(input);
-               if (debug != null && !debug.check_connection()) {
+
+               boolean connection_ok = true;
+
+               if (debug != null) {
+                       try {
+                               connection_ok = debug.check_connection();
+                       } catch (IOException ie) {
+                               debug.close();
+                               throw ie;
+                       } catch (InterruptedException ie) {
+                               debug.close();
+                               throw ie;
+                       }
+               }
+               if (!connection_ok) {
                        debug.close();
                        throw new IOException("Debug port not connected");
                }
        }
                        debug.close();
                        throw new IOException("Debug port not connected");
                }
        }
-}
\ No newline at end of file
+}