micropeak: Show error message if USB adapter open fails
authorKeith Packard <keithp@keithp.com>
Wed, 18 Aug 2021 03:02:05 +0000 (20:02 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 7 Sep 2021 06:07:56 +0000 (23:07 -0700)
Pop up an error dialog and *don't* show the download dialog as if the
open had worked.

Signed-off-by: Keith Packard <keithp@keithp.com>
micropeak/MicroDownload.java
micropeak/MicroPeak.java

index 7e3d1e593dfc6658d737902ec5546afecdffb905..4dcb7a360e928e2457b084bc0bc5d3d6d545c3cd 100644 (file)
@@ -190,12 +190,7 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList
        }
 
        public void start() {
-               try {
-                       serial = new MicroSerial(device);
-                       serial.set_log(this);
-               } catch (FileNotFoundException fe) {
-                       return;
-               }
+               serial.set_log(this);
                serial_thread = new Thread(this);
                serial_thread.start();
 
@@ -212,7 +207,7 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList
                setVisible(false);
        }
 
-       public MicroDownload(MicroPeak owner, AltosDevice device) {
+       public MicroDownload(MicroPeak owner, AltosDevice device, MicroSerial serial) {
                super (owner, "Download MicroPeak Data", false);
 
                int y = 0;
@@ -223,6 +218,7 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList
 
                this.owner = owner;
                this.device = device;
+               this.serial = serial;
 
                pane = getScrollablePane();
                pane.setLayout(new GridBagLayout());
index c34e874aaaa05b2708a17ef2f9c20ae2b65f143c..96fb33ba132d6a368e2436dfedb11fd98eaae256 100644 (file)
@@ -136,9 +136,18 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
 
        private void DownloadData() {
                AltosDevice     device = MicroDeviceDialog.show(this);
+               MicroSerial     serial = null;
+               try {
+                       serial = new MicroSerial(device);
+               } catch (FileNotFoundException fe) {
+                       JOptionPane.showMessageDialog(this,
+                                                     fe.getMessage(),
+                                                     "Cannot open device",
+                                                     JOptionPane.ERROR_MESSAGE);
+                       return;
+               }
 
-               if (device != null)
-                       new MicroDownload(this, device);
+               new MicroDownload(this, device, serial);
        }
 
        private void no_data() {