-
Notifications
You must be signed in to change notification settings - Fork 904
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
Discrepancy in returned number of read bytes in hid_get_feature_report() #182
Comments
Windows does it for you. Windows always uses a report id in its API (including that DeviceIoControl call), regardless of whether there's one on the bus. On the bus, there's no report ID if numbered reports are not being used, but there is if numbered reports are being used. In the API there's a report ID every time.
It's more complicated than that. It's an extra byte only when not using numbered reports.
Well that's not going to happen. It needs to be consistent across platforms, and I believe it is. Maybe the documentation should be updated to reflect the extra byte.
That's right. On the bus, there's no report ID at all transferred if you're not using numbered reports. HIDAPI is different. There is always a report number for these functions.
I believe it already is, and you haven't shown me an example where it is not. Do you have some code and a device which shows different values for this on different platforms? What device are you using anyway that has feature reports. It's fairly rare in commercial custom HID devices. Alan. |
Alan Ott pí¹e v Ne 17. 08. 2014 v 16:04 -0700:
It does not. Windows 7/8.1 returns 40 (in my case) which is the count
If it was consistent I wouldn't bother creating this issue. If you, like I can go ahead and create a patch and test it for you if you wish.
yes, of course. As I said above, I had a code working well under Linux
it's my own device, created using V-USB.
I've been searching for the simplest descriptor that would allow me Thanks, Petr |
You're right. Windows doesn't do what I thought it did. Fixed on the Windows side: Also fixed documentation in hidapi.h to reflect what we discussed. Thanks! |
Hi. I'm just reviewing hidapi to check the current state. Should this issue be closed? |
yes |
No, it broke #192 |
There's a problematic discrepancy between libusb's and windows implementation of hid_get_feature_report() for report ID = 0. The libusb's implementation contains a special code for zero report ID that adds 1 to number of returned bytes. However, the windows code does not do that. Thus the same code calling HIDAPI gets different number of read bytes when it's run on Linux than when it's run on Windows.
The API documentation says that "this function returns the number of bytes read". There's no note of extra byte for Report ID, contrary to the input parameter 'length'. Thus I'd say the libusb's implementation is wrong with adding 1 to the number of returned bytes.
Also, technically, the USB device sent only X bytes and the driver read only X bytes, not X+1. So I'd be inclined to removing the extra code from libusb's implementation. I realize that the returned number of read bytes is then different than the value sent in the 'length' parameter but that shouldn't matter as the length is mainly the size of the allocated buffer, not the number of bytes that are to be read.
I also realize that the buffer contains one more byte than what is returned as the number of read bytes. Hmmm. That's not consistent with result of the same call with non-zero report ID, right?
Anyway, please go ahead and fix it either way, it just needs to be consistent on all supported platforms so that the code calling HIDAPI does not have to have special code for each platform. Thank you!
The text was updated successfully, but these errors were encountered: