@@ -106,11 +106,24 @@ public class SerialMonitor extends ViewPart implements ISerialUser {
106
106
protected boolean myAutoScroll ; // is auto scroll on or off?
107
107
private static final String myFlagMonitor = "FmStatus" ; //$NON-NLS-1$
108
108
String uri = "h tt p://ba eye ns. i t/ec li pse/d ow nlo ad/mo nito rSta rt.ht m l?m=" ; //$NON-NLS-1$
109
+ private static SerialMonitor me = null ;
110
+
111
+ public static SerialMonitor getSerialMonitor () {
112
+ if (me == null ) {
113
+ me = new SerialMonitor ();
114
+ }
115
+ return me ;
116
+ }
109
117
110
118
/**
111
119
* The constructor.
112
120
*/
113
121
public SerialMonitor () {
122
+ if (me != null ) {
123
+ Common .log (new Status (IStatus .ERROR , ArduinoConst .CORE_PLUGIN_ID , "You can only have one serial monitor" ));
124
+
125
+ }
126
+ me = this ;
114
127
this .mySerialConnections = new LinkedHashMap <>(myMaxSerialPorts );
115
128
IThemeManager themeManager = PlatformUI .getWorkbench ().getThemeManager ();
116
129
ITheme currentTheme = themeManager .getCurrentTheme ();
@@ -356,7 +369,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
356
369
*
357
370
* @return the serial port selected in the combobox
358
371
*/
359
- Serial GetSelectedSerial () {
372
+ private Serial GetSelectedSerial () {
360
373
return GetSerial (this .mySerialPorts .getCombo ().getText ());
361
374
}
362
375
@@ -402,7 +415,7 @@ public void run() {
402
415
comportSelector .create ();
403
416
if (comportSelector .open () == Window .OK ) {
404
417
connectSerial (comportSelector .GetComPort (), comportSelector .GetBaudRate ());
405
- SerialPortsUpdated ();
418
+
406
419
}
407
420
}
408
421
};
@@ -414,15 +427,7 @@ public void run() {
414
427
this .myDisconnectSerialPort = new Action () {
415
428
@ Override
416
429
public void run () {
417
- Serial newSerial = GetSelectedSerial ();
418
- if (newSerial != null ) {
419
- SerialListener theListener = SerialMonitor .this .mySerialConnections .get (newSerial );
420
- SerialMonitor .this .mySerialConnections .remove (newSerial );
421
- newSerial .removeListener (theListener );
422
- newSerial .dispose ();
423
- theListener .dispose ();
424
- SerialPortsUpdated ();
425
- }
430
+ disConnectSerialPort (getSerialMonitor ().mySerialPorts .getCombo ().getText ());
426
431
}
427
432
};
428
433
this .myDisconnectSerialPort .setText (Messages .SerialMonitor_disconnected_from );
@@ -508,6 +513,7 @@ public void connectSerial(String ComPort, int BaudRate) {
508
513
theListener .event (System .getProperty ("line.separator" ) + Messages .SerialMonitor_connectedt_to + ComPort //$NON-NLS-1$
509
514
+ Messages .SerialMonitor_at + BaudRate + System .getProperty ("line.separator" )); //$NON-NLS-1$
510
515
this .mySerialConnections .put (newSerial , theListener );
516
+ SerialPortsUpdated ();
511
517
return ;
512
518
}
513
519
} else {
@@ -517,6 +523,18 @@ public void connectSerial(String ComPort, int BaudRate) {
517
523
518
524
}
519
525
526
+ public void disConnectSerialPort (String comPort ) {
527
+ Serial newSerial = GetSerial (comPort );
528
+ if (newSerial != null ) {
529
+ SerialListener theListener = SerialMonitor .this .mySerialConnections .get (newSerial );
530
+ SerialMonitor .this .mySerialConnections .remove (newSerial );
531
+ newSerial .removeListener (theListener );
532
+ newSerial .dispose ();
533
+ theListener .dispose ();
534
+ SerialPortsUpdated ();
535
+ }
536
+ }
537
+
520
538
/**
521
539
*
522
540
*/
0 commit comments