nyholku / purejavahidapi

Other
121 stars 69 forks source link

setOutputReport is blocking sometimes #65

Open denkovi1 opened 5 years ago

denkovi1 commented 5 years ago

Hello, OS: windows7 / windows10 JNA: 5.2.0

Sometimes the setOutputReport is blocking. This is happened while packets are sent very often. This can be simulated if you make something like that:

for (int j=0; j<1000; j++) { for (int i=0; i<1000; i++) res=openedDevice.setOutputReport((byte)0,in,in.length);

sleep(10); } Here, it blocks for 2-3 minutes max. The previous version we used (0.0.1) worked good and this problem does not exist there.

Thank you in advance for your help!

nyholku commented 5 years ago

There is no version 0.0.1, are you referring to the latest 0.0.10 ? If so what is the version you are using cause that is the latest?

denkovi1 commented 5 years ago

Hello, I have downloaded the previous library somewhere in MAR 2016 and used since now in my software, I am not sure which version it is - either 0.0.3 or 0.0.5. There was still openDeviceNonBlocking() and openDevice() methods. This version causing troubles in windows 10 especially after the last official upgrade. It won't list the HID devices I am using - MCP2200 When i downloaded the last version 0.0.10 - the windows 10 problem is gone, however the above problem appears - when many output reports are sent to the HID device during small interval of time, it hangs at this line in my code: int res=openedDevice.setOutputReport((byte)0,in,in.length); Also i am not sure if this may be the problem but in 0.0.3(0.0.5) i was using openDeviceNonBlocking() and now (0.0.10) since there is not such method, i use just openDevice(). Hope i managed to explain, Regards

denkovi1 commented 5 years ago

Hello again, some update. I found now the source code I have downloaded then - it really states 0.0.1. I can not find/remember from where it is downloaded but indeed there is special method openDeviceNonBlocking for windows in PureJavaHidApi.java:

/**

Now i don't see such method in this repository. I think this is the core of the problem and that's why it blocks. I can provide the whole source code i have (the so called 0.0.1)

MrHazee commented 5 years ago

Hi there Nyholku and denkovi1, I to can confirm the blocking-issue on win 10 and win 7 (same with both JNA 4.5.1 and 5.2.0). Exactly the same code on mac Mojave 10.14.3 works flawlessly. The problem seems to somehow be connected with the function Object invoke(Object[] args, Class<?> returnType, boolean allowObjects, int fixedArgs) line 406 in Funtion.java in JNA. My explanation here on is a bit fuzzy, (sorry for that) but I tried to print the variable called "result" at the end of that function, and every time I sent a certain message I got.. 0,1,1,0,0 ..on the console, except when it blocked, then I got 0,1,0,0 ..and then nothning.
I tried to put in a 1 ms sleep as the first thing in that method and that seemed to somehow solve the problem on my main computer.. but it didnt work on a different computer. So that is definitely not a soloution.

The blocking seems to occur more exactly at line 422 in Function.java: result = Integer.valueOf(Native.invokeInt(this, this.peer, callFlags, args)); ..which calls the function: static native int invokeInt(Function function, long fp, int callFlags, Object[] args);

I wouyld be BEYOND super grateful for any advice in the matter. Thanks

MrHazee commented 5 years ago

@denkovi1 I´m really stuck at this on win 10 and cant get my head around it, could you please provide the source code to the library that still has the openDeviceNonBlocking() method and does not block? best regards

denkovi1 commented 5 years ago

Hello, Hope this will help: https://github.com/denkovi1/purejavahidapi Regards

MrHazee commented 5 years ago

MAN DID THIS HELP?! It works like a charm.. If you would stand here I would kiss ya. Cant stress my gratitude enough! Thanks!!

denkovi1 commented 5 years ago

Thank you but I am not the developer of this branch. I just downloaded it years ago most probably from one of the forked repos of this project and i can not find the contributor anymore here. Please note that personally i found issues with the last Windows 10 upgrade. Some of the USB HID chips we use (not all of them but only some) are not listed. Again this is only for Windows 10 last upgrade and only for some chips. That was the reason I tried this library but here also there are problems in windows (the blocking issue). I am not expert in such low level HID programing, but hope this will help for improving this project. Cheers!

MrHazee commented 5 years ago

Yes I know and of course nyholku is the one who shold have the credit!! But Ive spent countless of hours trying to solve the problem with 3 or 4 different older versions that I tracked down at various old webpages and other apis but with no success.. anyway, im gratuful that you took the time to share it with me! Cheers