@@ -76,19 +76,52 @@ public class NRSerialPort
76
76
private String port = null ;
77
77
private boolean connected = false ;
78
78
private int baud = 115200 ;
79
+ private int parity = SerialPort .PARITY_NONE ;
80
+ private int dataBits = SerialPort .DATABITS_8 ;
81
+ private int stopBits = SerialPort .STOPBITS_1 ;
79
82
80
83
/**
81
84
* Class Constructor for a NRSerialPort with a given port and baudrate.
82
85
*
83
86
* @param port the port to connect to (i.e. COM6 or /dev/ttyUSB0)
84
87
* @param baud the baudrate to use (i.e. 9600 or 115200)
85
88
*/
89
+
90
+ public NRSerialPort (String port )
91
+ {
92
+ setPort (port );
93
+ }
94
+
86
95
public NRSerialPort (String port , int baud )
87
96
{
88
97
setPort (port );
89
98
setBaud (baud );
90
99
}
91
100
101
+ public NRSerialPort (String port , int baud , int parity )
102
+ {
103
+ setPort (port );
104
+ setBaud (baud );
105
+ setParity (parity );
106
+ }
107
+
108
+ public NRSerialPort (String port , int baud , int parity , int dataBits )
109
+ {
110
+ setPort (port );
111
+ setBaud (baud );
112
+ setParity (parity );
113
+ setDataBits (dataBits );
114
+ }
115
+
116
+ public NRSerialPort (String port , int baud , int parity , int dataBits , int stopBits )
117
+ {
118
+ setPort (port );
119
+ setBaud (baud );
120
+ setParity (parity );
121
+ setDataBits (dataBits );
122
+ setStopBits (stopBits );
123
+ }
124
+
92
125
public boolean connect ()
93
126
{
94
127
if (isConnected ())
@@ -103,7 +136,7 @@ public boolean connect()
103
136
serial = new RFC2217PortCreator ().createPort (port );
104
137
else
105
138
serial = new RxTxPortCreator ().createPort (port );
106
- serial .setSerialPortParams (getBaud (), SerialPort . DATABITS_8 , SerialPort . STOPBITS_1 , SerialPort . PARITY_NONE );
139
+ serial .setSerialPortParams (getBaud (), getDataBits (), getStopBits (), getParity () );
107
140
setConnected (true );
108
141
}
109
142
catch (NativeResourceException e )
@@ -236,6 +269,36 @@ public int getBaud()
236
269
return baud ;
237
270
}
238
271
272
+ public void setParity (int parity )
273
+ {
274
+ this .parity = parity ;
275
+ }
276
+
277
+ public int getParity ()
278
+ {
279
+ return this .parity ;
280
+ }
281
+
282
+ public void setStopBits (int stopBits )
283
+ {
284
+ this .stopBits = stopBits ;
285
+ }
286
+
287
+ public int getStopBits ()
288
+ {
289
+ return this .stopBits ;
290
+ }
291
+
292
+ public void setDataBits (int dataBits )
293
+ {
294
+ this .dataBits = dataBits ;
295
+ }
296
+
297
+ public int getDataBits ()
298
+ {
299
+ return this .dataBits ;
300
+ }
301
+
239
302
/**
240
303
* Enables RS485 half-duplex bus communication for Linux. The Linux kernel uses the RTS pin as bus enable. If you use a device that is configured via the Linux
241
304
* device tree, take care to add "uart-has-rtscts" and to configure the RTS GPIO correctly.
0 commit comments