From 4b80afbca1320750c6c8547dd087c92869040ff8 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 13 Jun 2009 21:28:15 +0000 Subject: [PATCH] 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). --- app/src/processing/app/Editor.java | 20 +++++++++++--------- app/src/processing/app/SerialMonitor.java | 3 +++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 9edf9b500..475735874 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -99,7 +99,7 @@ public class Editor extends JFrame implements RunnerListener { static JMenu serialMenu; static SerialMenuListener serialMenuListener; - static Map serialMonitors; + static SerialMonitor serialMonitor; EditorHeader header; EditorStatus status; @@ -174,7 +174,8 @@ public class Editor extends JFrame implements RunnerListener { //PdeKeywords keywords = new PdeKeywords(); //sketchbook = new Sketchbook(this); - if (serialMonitors == null) serialMonitors = new HashMap(); + if (serialMonitor == null) + serialMonitor = new SerialMonitor(Preferences.get("serial.port")); buildMenuBar(); @@ -851,6 +852,9 @@ public class Editor extends JFrame implements RunnerListener { String name = item.getText(); //System.out.println(item.getLabel()); 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")); } @@ -2152,6 +2156,9 @@ public class Editor extends JFrame implements RunnerListener { Thread t = new Thread(new Runnable() { public void run() { try { + serialMonitor.closeSerialPort(); + serialMonitor.setVisible(false); + boolean success = sketch.exportApplet(new Target( Base.getHardwarePath() + File.separator + "cores", Preferences.get("boards." + Preferences.get("board") + ".build.core"))); @@ -2210,13 +2217,8 @@ public class Editor extends JFrame implements RunnerListener { public void handleSerial() { - String port = Preferences.get("serial.port"); - - if (!serialMonitors.containsKey(port)) - serialMonitors.put(port, new SerialMonitor(port)); - - ((SerialMonitor) serialMonitors.get(port)).setVisible(true); - ((SerialMonitor) serialMonitors.get(port)).openSerialPort(); + serialMonitor.setVisible(true); + serialMonitor.openSerialPort(); } diff --git a/app/src/processing/app/SerialMonitor.java b/app/src/processing/app/SerialMonitor.java index 15ff2565e..8482ae15d 100644 --- a/app/src/processing/app/SerialMonitor.java +++ b/app/src/processing/app/SerialMonitor.java @@ -120,9 +120,12 @@ public class SerialMonitor extends JFrame implements MessageConsumer { } public void openSerialPort() { + if (serial != null) return; + try { statusLabel.setText("opening..."); serial = new Serial(port, serialRate); + while (serial.available() > 0) serial.read(); serial.addListener(this); statusLabel.setText(""); } catch (SerialException e) {