1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-02 13:24:12 +01:00

Going back to one serial monitor at a time, but closing it when you pick a new serial port from the Tools > Serial Port menu (and when you upload).

This commit is contained in:
David A. Mellis 2009-06-13 21:28:15 +00:00
parent b81a8f0309
commit 4b80afbca1
2 changed files with 14 additions and 9 deletions

View File

@ -99,7 +99,7 @@ public class Editor extends JFrame implements RunnerListener {
static JMenu serialMenu; static JMenu serialMenu;
static SerialMenuListener serialMenuListener; static SerialMenuListener serialMenuListener;
static Map serialMonitors; static SerialMonitor serialMonitor;
EditorHeader header; EditorHeader header;
EditorStatus status; EditorStatus status;
@ -174,7 +174,8 @@ public class Editor extends JFrame implements RunnerListener {
//PdeKeywords keywords = new PdeKeywords(); //PdeKeywords keywords = new PdeKeywords();
//sketchbook = new Sketchbook(this); //sketchbook = new Sketchbook(this);
if (serialMonitors == null) serialMonitors = new HashMap(); if (serialMonitor == null)
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
buildMenuBar(); buildMenuBar();
@ -851,6 +852,9 @@ public class Editor extends JFrame implements RunnerListener {
String name = item.getText(); String name = item.getText();
//System.out.println(item.getLabel()); //System.out.println(item.getLabel());
Preferences.set("serial.port", name); Preferences.set("serial.port", name);
serialMonitor.closeSerialPort();
serialMonitor.setVisible(false);
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
//System.out.println("set to " + get("serial.port")); //System.out.println("set to " + get("serial.port"));
} }
@ -2152,6 +2156,9 @@ public class Editor extends JFrame implements RunnerListener {
Thread t = new Thread(new Runnable() { Thread t = new Thread(new Runnable() {
public void run() { public void run() {
try { try {
serialMonitor.closeSerialPort();
serialMonitor.setVisible(false);
boolean success = sketch.exportApplet(new Target( boolean success = sketch.exportApplet(new Target(
Base.getHardwarePath() + File.separator + "cores", Base.getHardwarePath() + File.separator + "cores",
Preferences.get("boards." + Preferences.get("board") + ".build.core"))); Preferences.get("boards." + Preferences.get("board") + ".build.core")));
@ -2210,13 +2217,8 @@ public class Editor extends JFrame implements RunnerListener {
public void handleSerial() { public void handleSerial() {
String port = Preferences.get("serial.port"); serialMonitor.setVisible(true);
serialMonitor.openSerialPort();
if (!serialMonitors.containsKey(port))
serialMonitors.put(port, new SerialMonitor(port));
((SerialMonitor) serialMonitors.get(port)).setVisible(true);
((SerialMonitor) serialMonitors.get(port)).openSerialPort();
} }

View File

@ -120,9 +120,12 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
} }
public void openSerialPort() { public void openSerialPort() {
if (serial != null) return;
try { try {
statusLabel.setText("opening..."); statusLabel.setText("opening...");
serial = new Serial(port, serialRate); serial = new Serial(port, serialRate);
while (serial.available() > 0) serial.read();
serial.addListener(this); serial.addListener(this);
statusLabel.setText(""); statusLabel.setText("");
} catch (SerialException e) { } catch (SerialException e) {