Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AlainCo opened this issue Feb 22, 2018 · 3 comments

Comments

@AlainCo
Copy link

AlainCo commented Feb 22, 2018

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
Copy link
Author

AlainCo commented Feb 22, 2018

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
Copy link
Owner

nyholku commented Feb 22, 2018

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

@AlainCo
Copy link
Author

AlainCo commented Feb 23, 2018

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

nsaney added a commit to nsaney/purejavahidapi that referenced this issue Apr 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants