mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
close SerialMonitor when port goes away suddenly (as when user presses Leonardo reset button)
This commit is contained in:
parent
ae5d5c0c00
commit
e9a00eb38f
@ -28,8 +28,10 @@ import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.text.*;
|
||||
import gnu.io.CommPortIdentifier;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
public class SerialMonitor extends JFrame implements MessageConsumer, Runnable {
|
||||
private Serial serial;
|
||||
private String port;
|
||||
private JTextArea textArea;
|
||||
@ -171,6 +173,9 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Thread thread = new Thread(this);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
protected void setPlacement(int[] location) {
|
||||
@ -228,4 +233,26 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (!Thread.interrupted()) {
|
||||
if (serial != null) {
|
||||
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
||||
boolean portStillHere = false;
|
||||
while (portList.hasMoreElements()) {
|
||||
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
|
||||
if (portId.getName().equals(port)) {
|
||||
portStillHere = true;
|
||||
}
|
||||
}
|
||||
if (!portStillHere) {
|
||||
closeSerialPort();
|
||||
setVisible(false);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user