Removed using of "invockedByPortList" parameter. Using of F_GETFL/F_SETFL has no effect on already opened port
This commit is contained in:
parent
49c677a663
commit
f4e725252f
|
@ -1,5 +1,5 @@
|
|||
/* jSSC (Java Simple Serial Connector) - serial port communication library.
|
||||
* © Alexey Sokolov (scream3r), 2010-2011.
|
||||
* © Alexey Sokolov (scream3r), 2010-2013.
|
||||
*
|
||||
* This file is part of jSSC.
|
||||
*
|
||||
|
@ -51,30 +51,28 @@
|
|||
* Port opening
|
||||
* In 2.2.0 added useTIOCEXCL and invokedByPortList
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_jssc_SerialNativeInterface_openPort(JNIEnv *env, jobject object, jstring portName, jboolean useTIOCEXCL, jboolean invokedByPortList){
|
||||
JNIEXPORT jint JNICALL Java_jssc_SerialNativeInterface_openPort(JNIEnv *env, jobject object, jstring portName, jboolean useTIOCEXCL){
|
||||
const char* port = env->GetStringUTFChars(portName, JNI_FALSE);
|
||||
jint hComm;
|
||||
hComm = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if(hComm != -1){
|
||||
//since 2.2.0 ->
|
||||
//since 2.2.0 -> (check termios structure for separating real serial devices from others)
|
||||
termios *settings = new termios();
|
||||
if(tcgetattr(hComm, settings) == 0){
|
||||
//<- since 2.2.0
|
||||
#if defined TIOCEXCL && !defined __SunOS
|
||||
if(useTIOCEXCL == JNI_TRUE){//since 2.2.0
|
||||
ioctl(hComm, TIOCEXCL);//since 0.9
|
||||
if(useTIOCEXCL == JNI_TRUE){
|
||||
ioctl(hComm, TIOCEXCL);
|
||||
}
|
||||
#endif
|
||||
if(invokedByPortList == JNI_FALSE){//since 2.2.0 (should not change any flags while using port list, because port can be opened by another application)
|
||||
int flags = fcntl(hComm, F_GETFL, 0);
|
||||
flags &= ~O_NDELAY;
|
||||
fcntl(hComm, F_SETFL, flags);
|
||||
}
|
||||
int flags = fcntl(hComm, F_GETFL, 0);
|
||||
flags &= ~O_NDELAY;
|
||||
fcntl(hComm, F_SETFL, flags);
|
||||
}
|
||||
else {
|
||||
hComm = -2;
|
||||
}
|
||||
delete settings;
|
||||
//<- since 2.2.0
|
||||
}
|
||||
else {//since 0.9 ->
|
||||
if(errno == EBUSY){//Port busy
|
||||
|
|
|
@ -42,10 +42,10 @@ extern "C" {
|
|||
/*
|
||||
* Class: jssc_SerialNativeInterface
|
||||
* Method: openPort
|
||||
* Signature: (Ljava/lang/String;ZZ)I
|
||||
* Signature: (Ljava/lang/String;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_jssc_SerialNativeInterface_openPort
|
||||
(JNIEnv *, jobject, jstring, jboolean, jboolean);
|
||||
(JNIEnv *, jobject, jstring, jboolean);
|
||||
|
||||
/*
|
||||
* Class: jssc_SerialNativeInterface
|
||||
|
|
|
@ -259,13 +259,10 @@ public class SerialNativeInterface {
|
|||
*
|
||||
* @param portName name of port for opening
|
||||
* @param useTIOCEXCL enable/disable using of <b>TIOCEXCL</b>. Take effect only on *nix based systems.
|
||||
* Ignored if invokedByPortList == true, and always igored on Windows
|
||||
* @param invokedByPortList if <b>true</b> - open port only for checking handle, not for working.
|
||||
* Take effect only on *nix based systems. If invokedByPortList == true value of <b>useTIOCEXCL</b> will be ignored
|
||||
*
|
||||
* @return handle of opened port or -1 if opening of the port was unsuccessful
|
||||
*/
|
||||
public native int openPort(String portName, boolean useTIOCEXCL, boolean invokedByPortList);
|
||||
public native int openPort(String portName, boolean useTIOCEXCL);
|
||||
|
||||
/**
|
||||
* Setting the parameters of opened port
|
||||
|
|
|
@ -146,7 +146,7 @@ public class SerialPort {
|
|||
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_ALREADY_OPENED);
|
||||
}
|
||||
if(portName != null){
|
||||
portHandle = serialInterface.openPort(portName, true, false);
|
||||
portHandle = serialInterface.openPort(portName, true);
|
||||
}
|
||||
else {
|
||||
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_NULL_NOT_PERMITTED);//since 2.1.0 -> NULL port name fix
|
||||
|
|
Loading…
Reference in New Issue