Skip to content

Commit ab48abd

Browse files
committed
Added DTR checkbox for serial monitor #394
1 parent c707e0e commit ab48abd

File tree

5 files changed

+53
-23
lines changed

5 files changed

+53
-23
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/arduino/Serial.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public static Vector<String> list() {
9898

9999
int stopbits;
100100
boolean monitor = false;
101+
102+
// whether to pull DTR to GND during reset or not
103+
boolean dtr = true;
101104

102105
String PortName;
103106

@@ -106,12 +109,17 @@ public static Vector<String> list() {
106109
private List<MessageConsumer> fConsumers;
107110

108111
public Serial(String iname, int irate) {
109-
this(iname, irate, 'N', 8, 1.0f);
112+
this(iname, irate, 'N', 8, 1.0f, true);
113+
}
114+
115+
public Serial(String iname, int irate, boolean dtr) {
116+
this(iname, irate, 'N', 8, 1.0f, dtr);
110117
}
111118

112-
public Serial(String iname, int irate, char iparity, int idatabits, float istopbits) {
119+
public Serial(String iname, int irate, char iparity, int idatabits, float istopbits, boolean dtr) {
113120
this.PortName = iname;
114121
this.rate = irate;
122+
this.dtr = dtr;
115123

116124
this.parity = SerialPort.PARITY_NONE;
117125
if (iparity == 'E')
@@ -236,15 +244,18 @@ public void registerService() {
236244
}
237245

238246
public void reset() {
239-
setDTR(false);
247+
if(this.dtr){
248+
setDTR(false);
249+
}
240250
setRTS(false);
241251

242252
try {
243253
Thread.sleep(100);
244254
} catch (InterruptedException e) {// JABA is not going to add code
245255
}
246-
247-
setDTR(true);
256+
if(this.dtr){
257+
setDTR(true);
258+
}
248259
setRTS(true);
249260

250261
}

it.baeyens.arduino.monitor/src/it/baeyens/arduino/monitor/views/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class Messages extends NLS {
66
private static final String BUNDLE_NAME = "it.baeyens.arduino.monitor.views.messages"; //$NON-NLS-1$
77
public static String OpenSerialDialogBox_Select_the_baut_rate;
88
public static String OpenSerialDialogBox_Serial_port_to_connect_to;
9+
public static String OpenSerialDialogBox_Dtr;
910
public static String ScopeListener_buffer_overflow;
1011
public static String ScopeView_channel;
1112
public static String ScopeView_connected_to;

it.baeyens.arduino.monitor/src/it/baeyens/arduino/monitor/views/OpenSerialDialogBox.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.eclipse.swt.SWT;
88
import org.eclipse.swt.layout.GridData;
99
import org.eclipse.swt.layout.GridLayout;
10+
import org.eclipse.swt.widgets.Button;
1011
import org.eclipse.swt.widgets.Composite;
1112
import org.eclipse.swt.widgets.Control;
1213
import org.eclipse.swt.widgets.Label;
@@ -23,16 +24,19 @@ protected void okPressed() {
2324
// deleted after he close
2425
this.SelectedRate = Integer.parseInt(this.BaudRates.getCombo().getText());
2526
this.SelectedPort = this.SerialPorts.getCombo().getText();
27+
this.SelectedDtr = this.DtrCheckbox.getSelection();
2628
InstancePreferences.setGlobalValue(Const.KEY_SERIAlRATE, this.BaudRates.getCombo().getText());
2729
InstancePreferences.setGlobalValue(Const.KEY_SERIAlPORT, this.SelectedPort);
2830
super.okPressed();
2931
}
3032

3133
private ComboViewer SerialPorts;
3234
private ComboViewer BaudRates;
35+
private Button DtrCheckbox;
3336
// private ComboViewer LineEndings;
3437
private String SelectedPort;
3538
private int SelectedRate;
39+
private boolean SelectedDtr;
3640

3741
protected OpenSerialDialogBox(Shell parentShell) {
3842
super(parentShell);
@@ -78,6 +82,11 @@ protected Control createDialogArea(Composite parent) {
7882

7983
this.BaudRates.getCombo().setText(InstancePreferences.getGlobalString(Const.KEY_SERIAlRATE, Const.EMPTY_STRING));
8084
this.SerialPorts.getCombo().setText(InstancePreferences.getGlobalString(Const.KEY_SERIAlPORT, Const.EMPTY_STRING));
85+
86+
this.DtrCheckbox = new Button(parent, SWT.CHECK);
87+
this.DtrCheckbox.setText(Messages.OpenSerialDialogBox_Dtr);
88+
this.DtrCheckbox.setSelection(true);
89+
8190
return parent;
8291

8392
}
@@ -90,4 +99,8 @@ public int GetBaudRate() {
9099
return this.SelectedRate;
91100
}
92101

102+
public boolean GetDtr() {
103+
return this.SelectedDtr;
104+
}
105+
93106
}

it.baeyens.arduino.monitor/src/it/baeyens/arduino/monitor/views/SerialMonitor.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public void run() {
409409
OpenSerialDialogBox comportSelector = new OpenSerialDialogBox(SerialMonitor.this.myparent.getShell());
410410
comportSelector.create();
411411
if (comportSelector.open() == Window.OK) {
412-
connectSerial(comportSelector.GetComPort(), comportSelector.GetBaudRate());
412+
connectSerial(comportSelector.GetComPort(), comportSelector.GetBaudRate(), comportSelector.GetDtr());
413413

414414
}
415415
}
@@ -495,24 +495,28 @@ void SerialPortsUpdated() {
495495
* the bautrate to connect to the com port
496496
*/
497497
public void connectSerial(String ComPort, int BaudRate) {
498-
if (this.mySerialConnections.size() < myMaxSerialPorts) {
499-
int colorindex = this.mySerialConnections.size();
500-
Serial newSerial = new Serial(ComPort, BaudRate);
501-
if (newSerial.IsConnected()) {
502-
newSerial.registerService();
503-
SerialListener theListener = new SerialListener(this, colorindex);
504-
newSerial.addListener(theListener);
505-
theListener.event(System.getProperty("line.separator") + Messages.SerialMonitor_connectedt_to + ComPort //$NON-NLS-1$
506-
+ Messages.SerialMonitor_at + BaudRate + System.getProperty("line.separator")); //$NON-NLS-1$
507-
this.mySerialConnections.put(newSerial, theListener);
508-
SerialPortsUpdated();
509-
return;
510-
}
511-
} else {
512-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.SerialMonitor_no_more_serial_ports_supported, null));
513-
}
514-
498+
connectSerial(ComPort, BaudRate, true);
515499
}
500+
501+
public void connectSerial(String ComPort, int BaudRate, boolean dtr) {
502+
if (this.mySerialConnections.size() < myMaxSerialPorts) {
503+
int colorindex = this.mySerialConnections.size();
504+
Serial newSerial = new Serial(ComPort, BaudRate, dtr);
505+
if (newSerial.IsConnected()) {
506+
newSerial.registerService();
507+
SerialListener theListener = new SerialListener(this, colorindex);
508+
newSerial.addListener(theListener);
509+
theListener.event(System.getProperty("line.separator") + Messages.SerialMonitor_connectedt_to + ComPort //$NON-NLS-1$
510+
+ Messages.SerialMonitor_at + BaudRate + System.getProperty("line.separator")); //$NON-NLS-1$
511+
this.mySerialConnections.put(newSerial, theListener);
512+
SerialPortsUpdated();
513+
return;
514+
}
515+
} else {
516+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.SerialMonitor_no_more_serial_ports_supported, null));
517+
}
518+
519+
}
516520

517521
public void disConnectSerialPort(String comPort) {
518522
Serial newSerial = GetSerial(comPort);

it.baeyens.arduino.monitor/src/it/baeyens/arduino/monitor/views/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
OpenSerialDialogBox_Select_the_baut_rate=Select the baudrate:
22
OpenSerialDialogBox_Serial_port_to_connect_to=Serial port to connect to:
3+
OpenSerialDialogBox_Dtr=Pull DTR to GND during reset:
34
ScopeListener_buffer_overflow=buffer overflow in ScopeListener
45
ScopeView_channel=Channel
56
ScopeView_connected_to=connected to:

0 commit comments

Comments
 (0)