mirror of
https://github.com/arduino/Arduino.git
synced 2025-04-05 21:40:24 +02: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 JMenu serialMenu;
|
||||||
|
|
||||||
static SerialMenuListener serialMenuListener;
|
static SerialMenuListener serialMenuListener;
|
||||||
static SerialMonitor serialMonitor;
|
static Map serialMonitors;
|
||||||
|
|
||||||
EditorHeader header;
|
EditorHeader header;
|
||||||
EditorStatus status;
|
EditorStatus status;
|
||||||
@ -174,8 +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 (serialMonitor == null) serialMonitor = new SerialMonitor();
|
if (serialMonitors == null) serialMonitors = new HashMap();
|
||||||
|
|
||||||
buildMenuBar();
|
buildMenuBar();
|
||||||
|
|
||||||
// For rev 0120, placing things inside a JPanel
|
// For rev 0120, placing things inside a JPanel
|
||||||
@ -852,7 +852,6 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
//System.out.println(item.getLabel());
|
//System.out.println(item.getLabel());
|
||||||
Preferences.set("serial.port", name);
|
Preferences.set("serial.port", name);
|
||||||
//System.out.println("set to " + get("serial.port"));
|
//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) {
|
public void handleSerial() {
|
||||||
if (!showSerialMonitor && !serialMonitor.isVisible()) return;
|
String port = Preferences.get("serial.port");
|
||||||
|
|
||||||
serialMonitor.setVisible(true);
|
if (!serialMonitors.containsKey(port))
|
||||||
serialMonitor.openSerialPort(Preferences.get("serial.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;
|
break;
|
||||||
|
|
||||||
case SERIAL:
|
case SERIAL:
|
||||||
editor.handleSerial(true);
|
editor.handleSerial();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,13 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
|||||||
private JButton sendButton;
|
private JButton sendButton;
|
||||||
private JComboBox serialRates;
|
private JComboBox serialRates;
|
||||||
private JLabel statusLabel;
|
private JLabel statusLabel;
|
||||||
|
private int serialRate;
|
||||||
|
|
||||||
public SerialMonitor() {
|
public SerialMonitor(String port) {
|
||||||
|
super(port);
|
||||||
|
|
||||||
|
this.port = port;
|
||||||
|
|
||||||
addWindowListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
closeSerialPort();
|
closeSerialPort();
|
||||||
@ -90,16 +95,16 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
|||||||
for (int i = 0; i < serialRateStrings.length; i++)
|
for (int i = 0; i < serialRateStrings.length; i++)
|
||||||
serialRates.addItem(serialRateStrings[i] + " baud");
|
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() {
|
serialRates.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String wholeString = (String) serialRates.getSelectedItem();
|
String wholeString = (String) serialRates.getSelectedItem();
|
||||||
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
|
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
|
||||||
int rate = Integer.parseInt(rateString);
|
serialRate = Integer.parseInt(rateString);
|
||||||
Preferences.set("serial.debug_rate", rateString);
|
Preferences.set("serial.debug_rate", rateString);
|
||||||
String port = SerialMonitor.this.port;
|
|
||||||
closeSerialPort();
|
closeSerialPort();
|
||||||
openSerialPort(port);
|
openSerialPort();
|
||||||
}});
|
}});
|
||||||
|
|
||||||
pane.add(serialRates, BorderLayout.EAST);
|
pane.add(serialRates, BorderLayout.EAST);
|
||||||
@ -114,18 +119,11 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
|||||||
serial.write(s);
|
serial.write(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openSerialPort(String port) {
|
public void openSerialPort() {
|
||||||
if (port.equals(this.port))
|
|
||||||
return;
|
|
||||||
|
|
||||||
closeSerialPort();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
statusLabel.setText("opening...");
|
statusLabel.setText("opening...");
|
||||||
serial = new Serial(port);
|
serial = new Serial(port, serialRate);
|
||||||
serial.addListener(this);
|
serial.addListener(this);
|
||||||
setTitle(port);
|
|
||||||
this.port = port;
|
|
||||||
statusLabel.setText("");
|
statusLabel.setText("");
|
||||||
} catch (SerialException e) {
|
} catch (SerialException e) {
|
||||||
statusLabel.setText(e.getMessage());
|
statusLabel.setText(e.getMessage());
|
||||||
@ -138,7 +136,6 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
|||||||
textArea.setText("");
|
textArea.setText("");
|
||||||
serial.dispose();
|
serial.dispose();
|
||||||
serial = null;
|
serial = null;
|
||||||
port = null;
|
|
||||||
statusLabel.setText("");
|
statusLabel.setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user