altosui: Open serial device at 'new' time. Prohibit duplicate opens.
[fw/altos] / ao-tools / altosui / AltosEepromDownload.java
index bd9e4b4853920297569fdb7f6baa818f1b593d9d..8996b9243a5284cc8a5b2606a6d15abc648e653b 100644 (file)
@@ -244,12 +244,11 @@ public class AltosEepromDownload implements Runnable {
                frame = given_frame;
                device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
 
-               serial_line = new AltosSerial();
                remote = false;
 
                if (device != null) {
                        try {
-                               serial_line.open(device);
+                               serial_line = new AltosSerial(device);
                                if (!device.matchProduct(AltosDevice.product_telemetrum))
                                        remote = true;
                                eeprom_thread = new Thread(this);
@@ -260,6 +259,12 @@ public class AltosEepromDownload implements Runnable {
                                                                            device.getPath()),
                                                              "Cannot open target device",
                                                              JOptionPane.ERROR_MESSAGE);
+                       } catch (AltosSerialInUseException si) {
+                               JOptionPane.showMessageDialog(frame,
+                                                             String.format("Device \"%s\" already in use",
+                                                                           device.getPath()),
+                                                             "Device in use",
+                                                             JOptionPane.ERROR_MESSAGE);
                        } catch (IOException ee) {
                                JOptionPane.showMessageDialog(frame,
                                                              device.getPath(),