-
Notifications
You must be signed in to change notification settings - Fork 398
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
hid_get_input_report returns one byte more than hid_read, also how to deal with hid_get_feature_report #229
Comments
The code of hid_get_input_report contains: I compared this with the implementation in Google Chrome (WebHID backend), and they read the data using the same API, but do not increment the byte count: |
(Arriving here from a reference in another issue...) That is the documented behavior of Lines 370 to 376 in 6a01f3b
Lines 271 to 275 in 6a01f3b
Addendum That is at least a reasonable interpretation of the documentation for |
http://janaxelson.com/hidpage.htm |
Historical info about feature report.
List: libusb-devel On 09/04/2010 10:18 PM, Xiaofan Chen wrote:
...
ReadFile() will only give input reports which came back on the I was eventually able to figure it out, and if you look here: at the hid_get_feature_report() function, you'll see what works. ... skipped ... |
Ref from Microsoft, which is said not to be so clear. |
Please check my test result also. Test FW and libusb code hidapitester results: it seems input report is correct but feature report has an issue as it reads back 4 bytes.
|
I just purposefully send one more byte and here is the test result. No issues with the input report and feature report.
|
@JoergAtGithub something I've failed to ask you earlier: |
I am using hidapitester.
|
Form the code of hidapitester.c, it is using hid_read_timeout() for input report and hid_get_feature_report() for feature report read. So based on my test result hid_read_timeout() is correct for input report. hid_get_feature_report() is a bit wrong for feature report in terms of the bytes reading. hidapitester does not test the correctness of hid_get_input_report(). |
That's unfortunate. Do you have other way to test it? (maybe modify |
I will see what I can do. I need to brush up my C skills (very low anyway). Interesting under Linux it seems to me hid_get_feature_report() is correct. I am using Raspberry Pi 400 running Ubuntu Linux 64bit.
However I have issues with hid_read() under Linux.
|
No issues under macOS with my Mac Mini M1.
|
Yeah those are all different implementations, and the issue seem to be only with Win backend. As for Linux read - hidraw or libusb? In both cases you shouldn't have any issues, this seem weird. |
For the purpose if this test, I think the easiest way would be to replace all |
I will test under Windows later, but my quick fix does not produce good result under macOS.
|
This means you're not using numbered reports, but your device does use them (numbered reports). Report ID need to be explicitly specified, and be non-zero. |
Yes I already specified input report ID as 1 as the parameter for hidapitester. So looks like there are other problems somewhere. |
Looks like my quick fix is not correct. I got the same results under Windows.
|
Does you device/FW support sending syncronous input reports? |
The device supports reading input report using either interrupt transfer or control transfer. I have tested with libusb Windows HID backend. I got the same results using hidpytoy, it also use hid_read for input reports. And I got the same results with feature report that one extra byte is read using hidpytoy and hidapitester, so there is an issue with Windows hid_get_feature_report. I will not be surprised that hid_get_input_report has the same issue. |
I guess I've trusted (and didn't check so far) the original commit too much. |
FYI on the device FW and libusb test program. For this paticular device FW, libusb HID backend seems to work. But there are other cases it does not work. You can see this report ID is causing lots of problem for Windows HID related codes, due to the unclear documentation from Microsoft. My picusb repo: I need to have a minor fix to build under MSYS2 MinGW-w64.
|
My anlaysis below and I believe hidapi current codes are wrong. I have asked in the libusb-devel mailing list to confirm. The following article is from the Windows Hardware Developer site.
So you can see that HIDAPI is using ReadFile for the fetching of HID reports continuously with the https://github.com/libusb/hidapi/blob/master/windows/hid.c#L56 Historical reasons why Alan Ott chose to use DeviceIoControl() call and not HidD_GetXxx. So it seems to me that the Microsoft documentation may be a bit confusing to say the driver can use Now the question is the return data of the two IOCTLs (output buffer). From what I read, I believe
|
More proper fix for hidapitester:
And proposed fix to hidapi (including #232)
|
With the above patch, the results are the same as macOS and Linux. So unfortunately my device is not suitable to test hid_get_input_report(). But at least it confirms the issue on hid_get_feature_report.
|
@JoergAtGithub Did you test the device without a report ID? If that is tested, then I think #232 is good to go. |
No, I tested this only with devices with Report ID. I have to check for a device without Report ID, where hid_get_input_report works. Not sure if I have such a device. |
Answers from Tim Roberts (a top Windows driver expert in the wordd and USB expert) in libusb-devel mailing list. On Wed, Jun 16, 2021 at 12:21 AM Tim Roberts wrote:
|
@JoergAtGithub So #232 is good to go. Is it possible for you to create another pull request for the feature report? Thanks. |
Fixes: #229 This originally tested/confirmed by @JoergAtGithub and @mcuee. And confirmed the expected behavior by Tim Roberts https://sourceforge.net/p/libusb/mailman/message/37303650/.
hid_get_input_report returns one byte more than hid_read
If I read the same report using hid_get_input_report and than with hid_read, the return value is I get different number of byes read as return value.
This is for the case of a single input report (I reported a maybe related issue about for the case of two input reports here #210 )
This occurs on Windows 7 with HIDAPI 0.10.0
The text was updated successfully, but these errors were encountered: