File tree 1 file changed +28
-1
lines changed
1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change 28
28
import javax .swing .border .*;
29
29
import javax .swing .event .*;
30
30
import javax .swing .text .*;
31
+ import gnu .io .CommPortIdentifier ;
32
+ import java .util .Enumeration ;
31
33
32
- public class SerialMonitor extends JFrame implements MessageConsumer {
34
+ public class SerialMonitor extends JFrame implements MessageConsumer , Runnable {
33
35
private Serial serial ;
34
36
private String port ;
35
37
private JTextArea textArea ;
@@ -171,6 +173,9 @@ public void actionPerformed(ActionEvent event) {
171
173
}
172
174
}
173
175
}
176
+
177
+ Thread thread = new Thread (this );
178
+ thread .start ();
174
179
}
175
180
176
181
protected void setPlacement (int [] location ) {
@@ -228,4 +233,26 @@ public void run() {
228
233
}
229
234
}});
230
235
}
236
+
237
+ public void run () {
238
+ while (!Thread .interrupted ()) {
239
+ if (serial != null ) {
240
+ Enumeration portList = CommPortIdentifier .getPortIdentifiers ();
241
+ boolean portStillHere = false ;
242
+ while (portList .hasMoreElements ()) {
243
+ CommPortIdentifier portId = (CommPortIdentifier ) portList .nextElement ();
244
+ if (portId .getName ().equals (port )) {
245
+ portStillHere = true ;
246
+ }
247
+ }
248
+ if (!portStillHere ) {
249
+ closeSerialPort ();
250
+ setVisible (false );
251
+ }
252
+ try {
253
+ Thread .sleep (100 );
254
+ } catch (InterruptedException ex ) { }
255
+ }
256
+ }
257
+ }
231
258
}
You can’t perform that action at this time.
0 commit comments