Ensure that timeouts are always set last after other configuration changes
This commit is contained in:
parent
5d96988de3
commit
0beac32ab4
|
@ -137,8 +137,7 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_openPortNative(
|
|||
}
|
||||
|
||||
// Configure the port parameters and timeouts
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD) &&
|
||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD))
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD))
|
||||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
||||
else
|
||||
{
|
||||
|
@ -243,7 +242,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
}*/
|
||||
if (baudRateCode == 0) // Set custom baud rate
|
||||
setBaudRate(serialPortFD, baudRate);
|
||||
return ((retVal == 0) ? JNI_TRUE : JNI_FALSE);
|
||||
return ((retVal == 0) && Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD) ? JNI_TRUE : JNI_FALSE);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
|
|
|
@ -127,8 +127,7 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_openPortNative(
|
|||
tcsetattr(serialPortFD, TCSANOW, &options);
|
||||
|
||||
// Configure the port parameters and timeouts
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD) &&
|
||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD))
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD))
|
||||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
||||
else
|
||||
{
|
||||
|
@ -195,7 +194,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
ioctl(serialPortFD, TIOCEXCL); // Block non-root users from opening this port
|
||||
if (baudRateCode == 0) // Set custom baud rate
|
||||
setBaudRate(serialPortFD, baudRate);
|
||||
return ((retVal == 0) ? JNI_TRUE : JNI_FALSE);
|
||||
return ((retVal == 0) && Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD) ? JNI_TRUE : JNI_FALSE);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
|
|
|
@ -178,8 +178,7 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_openPortNative(
|
|||
tcsetattr(serialPortFD, TCSANOW, &options);
|
||||
|
||||
// Configure the port parameters and timeouts
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD) &&
|
||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD))
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD))
|
||||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
||||
else
|
||||
{
|
||||
|
@ -244,7 +243,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
speed_t speed = (speed_t)baudRate;
|
||||
ioctl(serialPortFD, IOSSIOSPEED, &speed);
|
||||
}
|
||||
return ((retVal == 0) ? JNI_TRUE : JNI_FALSE);
|
||||
return ((retVal == 0) && Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD) ? JNI_TRUE : JNI_FALSE);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
|
|
|
@ -257,8 +257,7 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_openPortNative(
|
|||
if ((serialPortHandle = CreateFile(portName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED, NULL)) != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
// Configure the port parameters and timeouts
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, (jlong)serialPortHandle) &&
|
||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, (jlong)serialPortHandle))
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, (jlong)serialPortHandle))
|
||||
env->SetBooleanField(obj, isOpenedField, JNI_TRUE);
|
||||
else
|
||||
{
|
||||
|
@ -330,7 +329,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
dcbSerialParams.XoffChar = (char)19;
|
||||
|
||||
// Apply changes
|
||||
return SetCommState(serialPortHandle, &dcbSerialParams);
|
||||
return SetCommState(serialPortHandle, &dcbSerialParams) && Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
|
|
Loading…
Reference in New Issue