Skip to content

Commit a49f1b2

Browse files
author
Federico Fissore
committed
Added default fallback values to serial parameters used in Serial constructor. Fixes #3381
1 parent 380b147 commit a49f1b2

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

arduino-core/src/processing/app/PreferencesData.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ static public void setInteger(String key, int value) {
195195
set(key, String.valueOf(value));
196196
}
197197

198+
static public float getFloat(String attribute, float defaultValue) {
199+
if (has(attribute)) {
200+
return getFloat(attribute);
201+
}
202+
203+
return defaultValue;
204+
}
205+
206+
static public float getFloat(String attribute) {
207+
return Float.parseFloat(get(attribute));
208+
}
209+
198210
// get a copy of the Preferences
199211
static public PreferencesMap getMap() {
200212
return new PreferencesMap(prefs);

arduino-core/src/processing/app/Serial.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,30 @@ public class Serial implements SerialPortEventListener {
4949

5050
public Serial() throws SerialException {
5151
this(PreferencesData.get("serial.port"),
52-
PreferencesData.getInteger("serial.debug_rate"),
53-
PreferencesData.get("serial.parity").charAt(0),
54-
PreferencesData.getInteger("serial.databits"),
55-
Float.parseFloat(PreferencesData.get("serial.stopbits")));
52+
PreferencesData.getInteger("serial.debug_rate", 9600),
53+
PreferencesData.get("serial.parity", "N").charAt(0),
54+
PreferencesData.getInteger("serial.databits", 8),
55+
PreferencesData.getFloat("serial.stopbits", 1));
5656
}
5757

5858
public Serial(int irate) throws SerialException {
5959
this(PreferencesData.get("serial.port"), irate,
60-
PreferencesData.get("serial.parity").charAt(0),
61-
PreferencesData.getInteger("serial.databits"),
62-
Float.parseFloat(PreferencesData.get("serial.stopbits")));
60+
PreferencesData.get("serial.parity", "N").charAt(0),
61+
PreferencesData.getInteger("serial.databits", 8),
62+
PreferencesData.getFloat("serial.stopbits", 1));
6363
}
6464

6565
public Serial(String iname, int irate) throws SerialException {
66-
this(iname, irate, PreferencesData.get("serial.parity").charAt(0),
67-
PreferencesData.getInteger("serial.databits"),
68-
Float.parseFloat(PreferencesData.get("serial.stopbits")));
66+
this(iname, irate, PreferencesData.get("serial.parity", "N").charAt(0),
67+
PreferencesData.getInteger("serial.databits", 8),
68+
PreferencesData.getFloat("serial.stopbits", 1));
6969
}
7070

7171
public Serial(String iname) throws SerialException {
72-
this(iname, PreferencesData.getInteger("serial.debug_rate"),
73-
PreferencesData.get("serial.parity").charAt(0),
74-
PreferencesData.getInteger("serial.databits"),
75-
Float.parseFloat(PreferencesData.get("serial.stopbits")));
72+
this(iname, PreferencesData.getInteger("serial.debug_rate", 9600),
73+
PreferencesData.get("serial.parity", "N").charAt(0),
74+
PreferencesData.getInteger("serial.databits", 8),
75+
PreferencesData.getFloat("serial.stopbits", 1));
7676
}
7777

7878
public static boolean touchForCDCReset(String iname) throws SerialException {

0 commit comments

Comments
 (0)