Skip to content

Commit a9b6a00

Browse files
committed
Added support of "int flags" for "setParams()" method, and also added flags PARAMS_FLAG_IGNPAR, PARAMS_FLAG_PARMRK for changing state of INGPAR, PARMRK in _nix based version of jSSC.
1 parent d57c122 commit a9b6a00

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

src/cpp/_nix_based/jssc.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,19 @@ int getDataBitsByNum(jint byteSize) {
220220
}
221221
}
222222

223+
//since 2.6.0 ->
224+
const jint PARAMS_FLAG_IGNPAR = 1;
225+
const jint PARAMS_FLAG_PARMRK = 2;
226+
//<- since 2.6.0
227+
223228
/* OK */
224229
/*
225230
* Set serial port settings
231+
*
232+
* In 2.6.0 added flags parameter
226233
*/
227234
JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_setParams
228-
(JNIEnv *env, jobject object, jlong portHandle, jint baudRate, jint byteSize, jint stopBits, jint parity, jboolean setRTS, jboolean setDTR){
235+
(JNIEnv *env, jobject object, jlong portHandle, jint baudRate, jint byteSize, jint stopBits, jint parity, jboolean setRTS, jboolean setDTR, jint flags){
229236
jboolean returnValue = JNI_FALSE;
230237

231238
speed_t baudRateValue = getBaudRateByNum(baudRate);
@@ -299,12 +306,21 @@ JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_setParams
299306
settings->c_cflag &= ~CRTSCTS;
300307
settings->c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOCTL | ECHOPRT | ECHOKE | ISIG | IEXTEN);
301308

302-
settings->c_iflag &= ~(IXON | IXOFF | IXANY | INPCK | PARMRK | ISTRIP | IGNBRK | BRKINT | INLCR | IGNCR| ICRNL);
309+
settings->c_iflag &= ~(IXON | IXOFF | IXANY | INPCK | IGNPAR | PARMRK | ISTRIP | IGNBRK | BRKINT | INLCR | IGNCR| ICRNL);
303310
#ifdef IUCLC
304311
settings->c_iflag &= ~IUCLC;
305312
#endif
306313
settings->c_oflag &= ~OPOST;
307314

315+
//since 2.6.0 ->
316+
if((flags & PARAMS_FLAG_IGNPAR) == PARAMS_FLAG_IGNPAR){
317+
settings->c_iflag |= IGNPAR;
318+
}
319+
if((flags & PARAMS_FLAG_PARMRK) == PARAMS_FLAG_PARMRK){
320+
settings->c_iflag |= PARMRK;
321+
}
322+
//<- since 2.6.0
323+
308324
//since 0.9 ->
309325
settings->c_cc[VMIN] = 0;
310326
settings->c_cc[VTIME] = 0;

src/cpp/jssc_SerialNativeInterface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ JNIEXPORT jlong JNICALL Java_jssc_SerialNativeInterface_openPort
5858
/*
5959
* Class: jssc_SerialNativeInterface
6060
* Method: setParams
61-
* Signature: (JIIIIZZ)Z
61+
* Signature: (JIIIIZZI)Z
6262
*/
6363
JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_setParams
64-
(JNIEnv *, jobject, jlong, jint, jint, jint, jint, jboolean, jboolean);
64+
(JNIEnv *, jobject, jlong, jint, jint, jint, jint, jboolean, jboolean, jint);
6565

6666
/*
6767
* Class: jssc_SerialNativeInterface

src/java/jssc/SerialNativeInterface.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
public class SerialNativeInterface {
3838

39-
private static final String libVersion = "2.5"; //jSSC-2.5.0 Release from 27.04.2013
39+
private static final String libVersion = "2.6"; //jSSC-2.5.0 Release from 27.04.2013
4040
private static final String libMinorSuffix = "0"; //since 0.9.0
4141

4242
public static final int OS_LINUX = 0;
@@ -280,7 +280,7 @@ public static String getLibraryMinorSuffix() {
280280
* Open port
281281
*
282282
* @param portName name of port for opening
283-
* @param useTIOCEXCL enable/disable using of <b>TIOCEXCL</b>. Take effect only on *nix based systems.
283+
* @param useTIOCEXCL enable/disable using of <b>TIOCEXCL</b>. Take effect only on *nix based systems
284284
*
285285
* @return handle of opened port or -1 if opening of the port was unsuccessful
286286
*/
@@ -296,10 +296,11 @@ public static String getLibraryMinorSuffix() {
296296
* @param parity parity
297297
* @param setRTS initial state of RTS line (ON/OFF)
298298
* @param setDTR initial state of DTR line (ON/OFF)
299+
* @param flags additional Native settings. Take effect only on *nix based systems
299300
*
300301
* @return If the operation is successfully completed, the method returns true, otherwise false
301302
*/
302-
public native boolean setParams(long handle, int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR);
303+
public native boolean setParams(long handle, int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR, int flags);
303304

304305
/**
305306
* Purge of input and output buffer

src/java/jssc/SerialPort.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public class SerialPort {
108108
public static final int ERROR_PARITY = 0x0004;
109109
//<- since 0.8
110110

111+
//since 2.6.0 ->
112+
private static final int PARAMS_FLAG_IGNPAR = 1;
113+
private static final int PARAMS_FLAG_PARMRK = 2;
114+
//<- since 2.6.0
115+
111116
public SerialPort(String portName) {
112117
this.portName = portName;
113118
serialInterface = new SerialNativeInterface();
@@ -180,14 +185,7 @@ else if(portHandle == SerialNativeInterface.ERR_INCORRECT_SERIAL_PORT){
180185
* @throws SerialPortException
181186
*/
182187
public boolean setParams(int baudRate, int dataBits, int stopBits, int parity) throws SerialPortException {
183-
checkPortOpened("setParams()");
184-
if(stopBits == 1){
185-
stopBits = 0;
186-
}
187-
else if(stopBits == 3){
188-
stopBits = 1;
189-
}
190-
return serialInterface.setParams(portHandle, baudRate, dataBits, stopBits, parity, true, true);
188+
return setParams(baudRate, dataBits, stopBits, parity, true, true);
191189
}
192190

193191
/**
@@ -214,7 +212,14 @@ public boolean setParams(int baudRate, int dataBits, int stopBits, int parity, b
214212
else if(stopBits == 3){
215213
stopBits = 1;
216214
}
217-
return serialInterface.setParams(portHandle, baudRate, dataBits, stopBits, parity, setRTS, setDTR);
215+
int flags = 0;
216+
if(System.getProperty("JSSC_IGNPAR") != null || System.getProperty("jssc_ignpar") != null){
217+
flags |= PARAMS_FLAG_IGNPAR;
218+
}
219+
if(System.getProperty("JSSC_PARMRK") != null || System.getProperty("jssc_parmrk") != null){
220+
flags |= PARAMS_FLAG_PARMRK;
221+
}
222+
return serialInterface.setParams(portHandle, baudRate, dataBits, stopBits, parity, setRTS, setDTR, flags);
218223
}
219224

220225
/**

0 commit comments

Comments
 (0)