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
|
// Configure the port parameters and timeouts
|
||||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD) &&
|
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD))
|
||||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD))
|
|
||||||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -243,7 +242,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
}*/
|
}*/
|
||||||
if (baudRateCode == 0) // Set custom baud rate
|
if (baudRateCode == 0) // Set custom baud rate
|
||||||
setBaudRate(serialPortFD, baudRate);
|
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)
|
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);
|
tcsetattr(serialPortFD, TCSANOW, &options);
|
||||||
|
|
||||||
// Configure the port parameters and timeouts
|
// Configure the port parameters and timeouts
|
||||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD) &&
|
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD))
|
||||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD))
|
|
||||||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
||||||
else
|
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
|
ioctl(serialPortFD, TIOCEXCL); // Block non-root users from opening this port
|
||||||
if (baudRateCode == 0) // Set custom baud rate
|
if (baudRateCode == 0) // Set custom baud rate
|
||||||
setBaudRate(serialPortFD, baudRate);
|
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)
|
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);
|
tcsetattr(serialPortFD, TCSANOW, &options);
|
||||||
|
|
||||||
// Configure the port parameters and timeouts
|
// Configure the port parameters and timeouts
|
||||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD) &&
|
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD))
|
||||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD))
|
|
||||||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -244,7 +243,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
speed_t speed = (speed_t)baudRate;
|
speed_t speed = (speed_t)baudRate;
|
||||||
ioctl(serialPortFD, IOSSIOSPEED, &speed);
|
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)
|
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)
|
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
|
// Configure the port parameters and timeouts
|
||||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, (jlong)serialPortHandle) &&
|
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, (jlong)serialPortHandle))
|
||||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, (jlong)serialPortHandle))
|
|
||||||
env->SetBooleanField(obj, isOpenedField, JNI_TRUE);
|
env->SetBooleanField(obj, isOpenedField, JNI_TRUE);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -330,7 +329,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
dcbSerialParams.XoffChar = (char)19;
|
dcbSerialParams.XoffChar = (char)19;
|
||||||
|
|
||||||
// Apply changes
|
// 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)
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
|
Loading…
Reference in New Issue