Allow Windows serial port to return after several failed attempts at closing.

This commit is contained in:
hedgecrw85 2015-11-19 13:32:16 -06:00
parent b9170ed848
commit 4939a18b2d
1 changed files with 3 additions and 2 deletions

View File

@ -500,7 +500,8 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat
PurgeComm(serialPortHandle, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR);
// Close port
while (!CloseHandle(serialPortHandle));
int numRetries = 10;
while (!CloseHandle(serialPortHandle) && (numRetries-- > 0));
serialPortHandle = INVALID_HANDLE_VALUE;
env->SetLongField(obj, serialPortHandleField, -1l);
env->SetBooleanField(obj, isOpenedField, JNI_FALSE);
@ -518,7 +519,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_bytesAvailable(J
if (!ClearCommError(serialPortHandle, NULL, &commInfo))
return -1;
DWORD numBytesAvailable = commInfo.cbInQue;
return (jint)numBytesAvailable;
}