Skip to content

Keep Serial Monitor open during upload #2809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
10 changes: 10 additions & 0 deletions app/src/processing/app/AbstractMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
protected JScrollPane scrollPane;
protected JTextField textField;
protected JButton sendButton;
protected JButton resetButton;
protected JCheckBox autoscrollBox;
protected JComboBox lineEndings;
protected JComboBox serialRates;
Expand Down Expand Up @@ -101,10 +102,12 @@ public void actionPerformed(ActionEvent event) {

textField = new JTextField(40);
sendButton = new JButton(_("Send"));
resetButton = new JButton(_("Send Reset"));

upperPane.add(textField);
upperPane.add(Box.createRigidArea(new Dimension(4, 0)));
upperPane.add(sendButton);
upperPane.add(resetButton);

getContentPane().add(upperPane, BorderLayout.NORTH);

Expand Down Expand Up @@ -188,6 +191,10 @@ public void onSendCommand(ActionListener listener) {
sendButton.addActionListener(listener);
}

public void onResetCommand(ActionListener listener) {
resetButton.addActionListener(listener);
}

protected void setPlacement(int[] location) {
setBounds(location[0], location[1], location[2], location[3]);
}
Expand Down Expand Up @@ -228,6 +235,9 @@ public String getAuthorizationKey() {

public abstract void close() throws Exception;

public abstract void openSerial() throws Exception;
public abstract void closeSerial() throws Exception;

public synchronized void addToUpdateBuffer(char buff[], int n) {
updateBuffer.append(buff, 0, n);
}
Expand Down
29 changes: 25 additions & 4 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2422,11 +2422,12 @@ synchronized public void handleExport(final boolean usingProgrammer) {
// DAM: in Arduino, this is upload
class DefaultExportHandler implements Runnable {
public void run() {
boolean serialMonitorWasOpen = false;

try {
if (serialMonitor != null) {
serialMonitor.close();
serialMonitor.setVisible(false);
serialMonitor.closeSerial();
serialMonitorWasOpen=true;
}

uploading = true;
Expand Down Expand Up @@ -2458,17 +2459,28 @@ public void run() {
uploading = false;
//toolbar.clear();
toolbar.deactivate(EditorToolbar.EXPORT);

try {
if ( (serialMonitor != null) && (serialMonitorWasOpen) ){
serialMonitor.openSerial();
}
} catch (Exception e) {
// we are in deep trouble....
e.printStackTrace();
}

}
}

// DAM: in Arduino, this is upload (with verbose output)
class DefaultExportAppHandler implements Runnable {
public void run() {
boolean serialMonitorWasOpen = false;

try {
if (serialMonitor != null) {
serialMonitor.close();
serialMonitor.setVisible(false);
serialMonitor.closeSerial();
serialMonitorWasOpen=true;
}

uploading = true;
Expand Down Expand Up @@ -2500,6 +2512,15 @@ public void run() {
uploading = false;
//toolbar.clear();
toolbar.deactivate(EditorToolbar.EXPORT);

try {
if ( (serialMonitor != null) && (serialMonitorWasOpen) ){
serialMonitor.openSerial();
}
} catch (Exception e) {
// uh, deep trouble....
e.printStackTrace();
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions app/src/processing/app/NetworkMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ public void run() {
});
}
}

@Override
public void openSerial() throws Exception {}

@Override
public void closeSerial() throws Exception {}


@Override
public synchronized void message(String s) {
Expand Down
27 changes: 24 additions & 3 deletions app/src/processing/app/SerialMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import static processing.app.I18n._;


@SuppressWarnings("serial")
public class SerialMonitor extends AbstractMonitor {

Expand Down Expand Up @@ -64,6 +65,18 @@ public void actionPerformed(ActionEvent e) {
send(textField.getText());
textField.setText("");
}
});

onResetCommand(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
serial.setDTR(true);
Thread.sleep(207); // Pfffffff.
serial.setDTR(false);
} catch (Exception se) {
se.printStackTrace(); // we are in deep trouble if this happens....
}
}
});
}

Expand All @@ -88,7 +101,7 @@ private void send(String s) {
}
}

public void open() throws Exception {
public void openSerial() throws Exception {
if (serial != null) return;

serial = new Serial(port, serialRate) {
Expand All @@ -98,8 +111,8 @@ protected void message(char buff[], int n) {
}
};
}

public void close() throws Exception {
public void closeSerial() throws Exception {
if (serial != null) {
int[] location = getPlacement();
String locationStr = PApplet.join(PApplet.str(location), ",");
Expand All @@ -110,4 +123,12 @@ public void close() throws Exception {
}
}

public void open() throws Exception {
openSerial();
}

public void close() throws Exception {
closeSerial();
}

}
2 changes: 1 addition & 1 deletion arduino-core/src/processing/app/Serial.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public Serial(String iname, int irate, char iparity, int idatabits, float istopb
try {
port = new SerialPort(iname);
port.openPort();
port.setParams(rate, databits, stopbits, parity, true, true);
port.setParams(rate, databits, stopbits, parity, true, false);
port.addEventListener(this);
} catch (Exception e) {
throw new SerialException(I18n.format(_("Error opening serial port ''{0}''."), iname), e);
Expand Down