mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Now supporting multiple serial monitors open at once (one for each port).
This commit is contained in:
parent
678e09896f
commit
b81a8f0309
@ -99,7 +99,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
static JMenu serialMenu;
|
||||
|
||||
static SerialMenuListener serialMenuListener;
|
||||
static SerialMonitor serialMonitor;
|
||||
static Map serialMonitors;
|
||||
|
||||
EditorHeader header;
|
||||
EditorStatus status;
|
||||
@ -174,8 +174,8 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
//PdeKeywords keywords = new PdeKeywords();
|
||||
//sketchbook = new Sketchbook(this);
|
||||
|
||||
if (serialMonitor == null) serialMonitor = new SerialMonitor();
|
||||
|
||||
if (serialMonitors == null) serialMonitors = new HashMap();
|
||||
|
||||
buildMenuBar();
|
||||
|
||||
// For rev 0120, placing things inside a JPanel
|
||||
@ -852,7 +852,6 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
//System.out.println(item.getLabel());
|
||||
Preferences.set("serial.port", name);
|
||||
//System.out.println("set to " + get("serial.port"));
|
||||
handleSerial(false);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2210,11 +2209,14 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
}
|
||||
|
||||
|
||||
public void handleSerial(boolean showSerialMonitor) {
|
||||
if (!showSerialMonitor && !serialMonitor.isVisible()) return;
|
||||
|
||||
serialMonitor.setVisible(true);
|
||||
serialMonitor.openSerialPort(Preferences.get("serial.port"));
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -344,7 +344,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
break;
|
||||
|
||||
case SERIAL:
|
||||
editor.handleSerial(true);
|
||||
editor.handleSerial();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,13 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
private JButton sendButton;
|
||||
private JComboBox serialRates;
|
||||
private JLabel statusLabel;
|
||||
private int serialRate;
|
||||
|
||||
public SerialMonitor() {
|
||||
public SerialMonitor(String port) {
|
||||
super(port);
|
||||
|
||||
this.port = port;
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
closeSerialPort();
|
||||
@ -90,16 +95,16 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
for (int i = 0; i < serialRateStrings.length; i++)
|
||||
serialRates.addItem(serialRateStrings[i] + " baud");
|
||||
|
||||
serialRates.setSelectedItem(Preferences.get("serial.debug_rate") + " baud");
|
||||
serialRate = Preferences.getInteger("serial.debug_rate");
|
||||
serialRates.setSelectedItem(serialRate + " baud");
|
||||
serialRates.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String wholeString = (String) serialRates.getSelectedItem();
|
||||
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
|
||||
int rate = Integer.parseInt(rateString);
|
||||
serialRate = Integer.parseInt(rateString);
|
||||
Preferences.set("serial.debug_rate", rateString);
|
||||
String port = SerialMonitor.this.port;
|
||||
closeSerialPort();
|
||||
openSerialPort(port);
|
||||
openSerialPort();
|
||||
}});
|
||||
|
||||
pane.add(serialRates, BorderLayout.EAST);
|
||||
@ -114,18 +119,11 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
serial.write(s);
|
||||
}
|
||||
|
||||
public void openSerialPort(String port) {
|
||||
if (port.equals(this.port))
|
||||
return;
|
||||
|
||||
closeSerialPort();
|
||||
|
||||
public void openSerialPort() {
|
||||
try {
|
||||
statusLabel.setText("opening...");
|
||||
serial = new Serial(port);
|
||||
serial = new Serial(port, serialRate);
|
||||
serial.addListener(this);
|
||||
setTitle(port);
|
||||
this.port = port;
|
||||
statusLabel.setText("");
|
||||
} catch (SerialException e) {
|
||||
statusLabel.setText(e.getMessage());
|
||||
@ -138,7 +136,6 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
textArea.setText("");
|
||||
serial.dispose();
|
||||
serial = null;
|
||||
port = null;
|
||||
statusLabel.setText("");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user