altosui: Open serial device at 'new' time. Prohibit duplicate opens.
[fw/altos] / ao-tools / altosui / AltosConfig.java
index 30f7d541bd60b44d612bf8574b03052167fb02e5..09e204a9de3e9f7e7077937548d19c886f2db0f7 100644 (file)
@@ -231,10 +231,9 @@ public class AltosConfig implements Runnable, ActionListener {
                product = new string_ref("unknown");
 
                device = AltosDeviceDialog.show(owner, AltosDevice.product_any);
-               serial_line = new AltosSerial();
                if (device != null) {
                        try {
-                               serial_line.open(device);
+                               serial_line = new AltosSerial(device);
                                if (!device.matchProduct(AltosDevice.product_telemetrum))
                                        remote = true;
                                config_thread = new Thread(this);
@@ -245,6 +244,12 @@ public class AltosConfig implements Runnable, ActionListener {
                                                                            device.getPath()),
                                                              "Cannot open target device",
                                                              JOptionPane.ERROR_MESSAGE);
+                       } catch (AltosSerialInUseException si) {
+                               JOptionPane.showMessageDialog(owner,
+                                                             String.format("Device \"%s\" already in use",
+                                                                           device.getPath()),
+                                                             "Device in use",
+                                                             JOptionPane.ERROR_MESSAGE);
                        } catch (IOException ee) {
                                JOptionPane.showMessageDialog(owner,
                                                              device.getPath(),