Removed using of "invockedByPortList" parameter. Using of F_GETFL/F_SETFL has no effect on already opened port

This commit is contained in:
scream3r 2013-04-18 10:17:54 +04:00
parent 49c677a663
commit f4e725252f
4 changed files with 13 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library. /* 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. * This file is part of jSSC.
* *
@ -51,30 +51,28 @@
* Port opening * Port opening
* In 2.2.0 added useTIOCEXCL and invokedByPortList * 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); const char* port = env->GetStringUTFChars(portName, JNI_FALSE);
jint hComm; jint hComm;
hComm = open(port, O_RDWR | O_NOCTTY | O_NDELAY); hComm = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
if(hComm != -1){ 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(); termios *settings = new termios();
if(tcgetattr(hComm, settings) == 0){ if(tcgetattr(hComm, settings) == 0){
//<- since 2.2.0
#if defined TIOCEXCL && !defined __SunOS #if defined TIOCEXCL && !defined __SunOS
if(useTIOCEXCL == JNI_TRUE){//since 2.2.0 if(useTIOCEXCL == JNI_TRUE){
ioctl(hComm, TIOCEXCL);//since 0.9 ioctl(hComm, TIOCEXCL);
} }
#endif #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); int flags = fcntl(hComm, F_GETFL, 0);
flags &= ~O_NDELAY; flags &= ~O_NDELAY;
fcntl(hComm, F_SETFL, flags); fcntl(hComm, F_SETFL, flags);
} }
}
else { else {
hComm = -2; hComm = -2;
} }
delete settings; delete settings;
//<- since 2.2.0
} }
else {//since 0.9 -> else {//since 0.9 ->
if(errno == EBUSY){//Port busy if(errno == EBUSY){//Port busy

View File

@ -42,10 +42,10 @@ extern "C" {
/* /*
* Class: jssc_SerialNativeInterface * Class: jssc_SerialNativeInterface
* Method: openPort * Method: openPort
* Signature: (Ljava/lang/String;ZZ)I * Signature: (Ljava/lang/String;Z)I
*/ */
JNIEXPORT jint JNICALL Java_jssc_SerialNativeInterface_openPort JNIEXPORT jint JNICALL Java_jssc_SerialNativeInterface_openPort
(JNIEnv *, jobject, jstring, jboolean, jboolean); (JNIEnv *, jobject, jstring, jboolean);
/* /*
* Class: jssc_SerialNativeInterface * Class: jssc_SerialNativeInterface

View File

@ -259,13 +259,10 @@ public class SerialNativeInterface {
* *
* @param portName name of port for opening * @param portName name of port for opening
* @param useTIOCEXCL enable/disable using of <b>TIOCEXCL</b>. Take effect only on *nix based systems. * @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 * @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 * Setting the parameters of opened port

View File

@ -146,7 +146,7 @@ public class SerialPort {
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_ALREADY_OPENED); throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_ALREADY_OPENED);
} }
if(portName != null){ if(portName != null){
portHandle = serialInterface.openPort(portName, true, false); portHandle = serialInterface.openPort(portName, true);
} }
else { else {
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_NULL_NOT_PERMITTED);//since 2.1.0 -> NULL port name fix throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_NULL_NOT_PERMITTED);//since 2.1.0 -> NULL port name fix