@@ -146,6 +146,8 @@ public boolean test(Sketch sketch) {
146
146
147
147
private int numTools = 0 ;
148
148
149
+ public boolean avoidMultipleOperations = false ;
150
+
149
151
private final EditorToolbar toolbar ;
150
152
// these menus are shared so that they needn't be rebuilt for all windows
151
153
// each time a sketch is created, renamed, or moved.
@@ -198,7 +200,7 @@ public boolean test(Sketch sketch) {
198
200
private Runnable stopHandler ;
199
201
Runnable exportHandler ;
200
202
private Runnable exportAppHandler ;
201
-
203
+ private Runnable timeoutUploadHandler ;
202
204
203
205
public Editor (Base ibase , File file , int [] storedLocation , int [] defaultLocation , Platform platform ) throws Exception {
204
206
super ("Arduino" );
@@ -812,6 +814,9 @@ public void actionPerformed(ActionEvent e) {
812
814
portMenu = new JMenu (tr ("Port" ));
813
815
populatePortMenu ();
814
816
toolsMenu .add (portMenu );
817
+ item = new JMenuItem (tr ("Get Board Info" ));
818
+ item .addActionListener (e -> handleBoardInfo ());
819
+ toolsMenu .add (item );
815
820
toolsMenu .addSeparator ();
816
821
817
822
base .rebuildProgrammerMenu ();
@@ -1661,6 +1666,7 @@ private void resetHandlers() {
1661
1666
stopHandler = new DefaultStopHandler ();
1662
1667
exportHandler = new DefaultExportHandler ();
1663
1668
exportAppHandler = new DefaultExportAppHandler ();
1669
+ timeoutUploadHandler = new TimeoutUploadHandler ();
1664
1670
}
1665
1671
1666
1672
@@ -1992,6 +1998,7 @@ public void run() {
1992
1998
1993
1999
status .unprogress ();
1994
2000
toolbar .deactivateRun ();
2001
+ avoidMultipleOperations = false ;
1995
2002
}
1996
2003
}
1997
2004
@@ -2380,6 +2387,7 @@ synchronized public void handleExport(final boolean usingProgrammer) {
2380
2387
console .clear ();
2381
2388
status .progress (tr ("Uploading to I/O Board..." ));
2382
2389
2390
+ new Thread (timeoutUploadHandler ).start ();
2383
2391
new Thread (usingProgrammer ? exportAppHandler : exportHandler ).start ();
2384
2392
}
2385
2393
@@ -2419,6 +2427,7 @@ public void run() {
2419
2427
e .printStackTrace ();
2420
2428
} finally {
2421
2429
populatePortMenu ();
2430
+ avoidMultipleOperations = false ;
2422
2431
}
2423
2432
status .unprogress ();
2424
2433
uploading = false ;
@@ -2446,13 +2455,14 @@ private void resumeOrCloseSerialMonitor() {
2446
2455
}
2447
2456
}
2448
2457
try {
2449
- if (serialMonitor != null )
2450
- serialMonitor .resume (boardPort );
2451
- if (boardPort == null ) {
2452
- serialMonitor .close ();
2453
- handleSerial ();
2454
- } else {
2458
+ if (serialMonitor != null ) {
2455
2459
serialMonitor .resume (boardPort );
2460
+ if (boardPort == null ) {
2461
+ serialMonitor .close ();
2462
+ handleSerial ();
2463
+ } else {
2464
+ serialMonitor .resume (boardPort );
2465
+ }
2456
2466
}
2457
2467
} catch (Exception e ) {
2458
2468
statusError (e );
@@ -2513,6 +2523,7 @@ public void run() {
2513
2523
} catch (Exception e ) {
2514
2524
e .printStackTrace ();
2515
2525
} finally {
2526
+ avoidMultipleOperations = false ;
2516
2527
populatePortMenu ();
2517
2528
}
2518
2529
status .unprogress ();
@@ -2527,6 +2538,20 @@ public void run() {
2527
2538
}
2528
2539
}
2529
2540
2541
+ class TimeoutUploadHandler implements Runnable {
2542
+
2543
+ public void run () {
2544
+ try {
2545
+ //10 seconds, than reactivate upload functionality and let the programmer pid being killed
2546
+ Thread .sleep (1000 * 10 );
2547
+ if (uploading ) {
2548
+ avoidMultipleOperations = false ;
2549
+ }
2550
+ } catch (InterruptedException e ) {
2551
+ // noop
2552
+ }
2553
+ }
2554
+ }
2530
2555
2531
2556
public void handleSerial () {
2532
2557
if (serialPlotter != null ) {
@@ -2571,7 +2596,7 @@ public void handleSerial() {
2571
2596
2572
2597
// If currently uploading, disable the monitor (it will be later
2573
2598
// enabled when done uploading)
2574
- if (uploading ) {
2599
+ if (uploading || avoidMultipleOperations ) {
2575
2600
try {
2576
2601
serialMonitor .suspend ();
2577
2602
} catch (Exception e ) {
@@ -2595,8 +2620,10 @@ public void handleSerial() {
2595
2620
}
2596
2621
2597
2622
try {
2598
- serialMonitor .open ();
2599
2623
serialMonitor .setVisible (true );
2624
+ if (!avoidMultipleOperations ) {
2625
+ serialMonitor .open ();
2626
+ }
2600
2627
success = true ;
2601
2628
} catch (ConnectException e ) {
2602
2629
statusError (tr ("Unable to connect: is the sketch using the bridge?" ));
@@ -2743,6 +2770,59 @@ private void handleBurnBootloader() {
2743
2770
}).start ();
2744
2771
}
2745
2772
2773
+ private void handleBoardInfo () {
2774
+ console .clear ();
2775
+
2776
+ String selectedPort = PreferencesData .get ("serial.port" );
2777
+ List <BoardPort > ports = Base .getDiscoveryManager ().discovery ();
2778
+
2779
+ String label = "" ;
2780
+ String vid = "" ;
2781
+ String pid = "" ;
2782
+ String iserial = "" ;
2783
+ String protocol = "" ;
2784
+ boolean found = false ;
2785
+
2786
+ for (BoardPort port : ports ) {
2787
+ if (port .getAddress ().equals (selectedPort )) {
2788
+ label = port .getBoardName ();
2789
+ vid = port .getVID ();
2790
+ pid = port .getPID ();
2791
+ iserial = port .getISerial ();
2792
+ protocol = port .getProtocol ();
2793
+ found = true ;
2794
+ break ;
2795
+ }
2796
+ }
2797
+
2798
+ if (!found ) {
2799
+ statusNotice (tr ("Please select a port to obtain board info" ));
2800
+ return ;
2801
+ }
2802
+
2803
+ if (protocol .equals ("network" )) {
2804
+ statusNotice (tr ("Network port, can't obtain info" ));
2805
+ return ;
2806
+ }
2807
+
2808
+ if (vid == null || vid .equals ("" ) || vid .equals ("0000" )) {
2809
+ statusNotice (tr ("Native serial port, can't obtain info" ));
2810
+ return ;
2811
+ }
2812
+
2813
+ if (iserial == null || iserial .equals ("" )) {
2814
+ iserial = tr ("Upload any sketch to obtain it" );
2815
+ }
2816
+
2817
+ if (label == null ) {
2818
+ label = tr ("Unknown board" );
2819
+ }
2820
+
2821
+ String infos = I18n .format ("BN: {0}\n VID: {1}\n PID: {2}\n SN: {3}" , label , vid , pid , iserial );
2822
+ JTextArea textArea = new JTextArea (infos );
2823
+
2824
+ JOptionPane .showMessageDialog (this , textArea , tr ("Board Info" ), JOptionPane .PLAIN_MESSAGE );
2825
+ }
2746
2826
2747
2827
/**
2748
2828
* Handler for File → Page Setup.
0 commit comments