Allow Windows serial port to return after several failed attempts at closing.
This commit is contained in:
parent
b9170ed848
commit
4939a18b2d
|
@ -500,7 +500,8 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat
|
||||||
PurgeComm(serialPortHandle, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR);
|
PurgeComm(serialPortHandle, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR);
|
||||||
|
|
||||||
// Close port
|
// Close port
|
||||||
while (!CloseHandle(serialPortHandle));
|
int numRetries = 10;
|
||||||
|
while (!CloseHandle(serialPortHandle) && (numRetries-- > 0));
|
||||||
serialPortHandle = INVALID_HANDLE_VALUE;
|
serialPortHandle = INVALID_HANDLE_VALUE;
|
||||||
env->SetLongField(obj, serialPortHandleField, -1l);
|
env->SetLongField(obj, serialPortHandleField, -1l);
|
||||||
env->SetBooleanField(obj, isOpenedField, JNI_FALSE);
|
env->SetBooleanField(obj, isOpenedField, JNI_FALSE);
|
||||||
|
|
Loading…
Reference in New Issue