nyholku / purejavahidapi

Other
122 stars 69 forks source link

on HidDevice.close() get "GetOverlappedResult failed with GetLastError()==995" #51

Open AlainCo opened 6 years ago

AlainCo commented 6 years ago

Hi,

I'm using purejavahidapi to contact a HidDevice (a Ledger Nano S)

It works well, I can PureJavaHidApi.enumerateDevices() then PureJavaHidApi.openDevice(HidDeviceInfo) then HidDevice.setOutputReport() and I get a callback InputReportListener.onInputReport() with the data I expect.

but when I make the HidDevice.close() It shows an error message :

GetOverlappedResult failed with GetLastError()==995

from purejavahidapi.windows.HidDevice.runReadOnBackground() in: `if (!GetOverlappedResult(m_Handle, m_InputReportOverlapped, m_InputReportBytesRead, true/ wait /)) {

if (GetLastError() == ERROR_DEVICE_NOT_CONNECTED)
    break; // early exit if the device disappears

System.out.println("GetOverlappedResult failed with GetLastError()==" + GetLastError());

}`

All seems OK, but the error message is not normal... Maybe I made a mistake in the call sequences...

Beside that, using a Logger like slf4j may helps to make the code more generic...

(By the way, thanks for the core functionality, it got me out of trouble.)

AlainCo commented 6 years ago

I propose this patch that seems to solve my problem, without too much impact out of the close() function :

`if (!GetOverlappedResult(m_Handle, m_InputReportOverlapped, m_InputReportBytesRead, true/ wait /)) {

    if (GetLastError() == ERROR_DEVICE_NOT_CONNECTED)
                break; // early exit if the device disappears

    if(m_StopThread && GetLastError() == ERROR_OPERATION_ABORTED)
                break;// on close

    System.out.println("GetOverlappedResult failed with GetLastError()==" + GetLastError());

} `

nyholku commented 6 years ago

Looks good to me, thanks I will try to put that in when I get a minute of time to that.

AlainCo commented 6 years ago

nice. NB: I'm newbie on git, and I cannot push with confidence