RFC: to include hidapitester as it is a very useful tool for debugging #285
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi#285
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
hidtest is using a test device based on modified Microchip Simple HID demo. It can be kept as an example but not that useful as a test tool for the project.
hidapitester is an excellent tool for testing of HID devices and HIDAPI. It will be good to include it in HIDAPI.
https://github.com/todbot/hidapitester
Only issue to include hidapitester is probably the GPL 3 license, which may or may not be a problem. I do not see it as a problem. But if some people see it as a problem, we can ask @todbot to see if he is willing to change the license.
@todbot How do you like the idea of including hidapitester in HIDAPI project?
Sounds great to me
I can change the license to whatever is most useful
HIDAPI license:
https://github.com/libusb/hidapi/blob/master/LICENSE.txt
hidapitester is already licensed under GPL3, just need to add the other two licenses.
Just FYI on the original hidtest, it is based on Microchip Demo FW (part of Microchip USB Stack) but I do not know if Alan Ott published the modified FW or not.
With the original FW (04d8:003f), here is the output.
With the enhancement for hidtest, it is of course worth to keep it now. But still I think hidapitester is a worthy add-on for the hidapi project as it is useful for different type of HID devices.
Example run log of hidapitester with a modified Lakeview Research Generic HID example.
FW: https://github.com/mcuee/picusb/tree/master/lvr_genhid_mod
Device: input report ID 1, output report ID 2, feature in report id 3 and feature output report id 4.
From the run log, it seems that my FW sent an extra byte for the Feature IN report. But I need to check again under different OS.
With the libusb test code, here is the output. Take note I purposefully send one more byte.
HIDAPI Test GUI seems to say the FW is correct.

Test under Linux (Raspberry Pi 400), hidapitester performs fine (tested with the hidraw backend).
@todbot It seems to me that hidapitester report reading of one more bytes for the Feature report under Windows. Not so sure if this is a problem with hidapitester or hidapi under Windows. If it is related to hidapi under Windows, the test gui seems to be correct. That is strange.
hidapitester is using hidapi directly, and not doing anything platform-specific. If there's a byte miscount, I think it's either in the testgui or the build of hidapitester you're using uses a hidapi with off-by-one errors (this used to exist in hidapi for certain situations, I forget the details at the moment)
The thing is that I am using the same version of hidapi here, the latest git. Test GUI is also from the latest git.
Supposedly the off-by-one has been fixed.
https://github.com/libusb/hidapi/pull/232 : for input report
github.com/libusb/hidapi@6fcb0bb228: for feature reportIt could be an hidapi issue under Windows in the end. Here is the test result from the original generic HID example here:
http://janaxelson.com/hidpage.htm
The C# based GUI application works fine. And the libusb1 hid backend works fine with the off-by-one fix https://github.com/libusb/libusb/pull/986
Host libusb1 codes:
https://github.com/mcuee/picusb/blob/master/lvr_genhid/libusb1_lvrhid4.c
C# GUI is working fine.

hidapitester output: total number of read bytes seems to be correct (2 bytes). But the data read seems to be not consistent between input report and feature report. I think we probably need to report reading 3 bytes for the Feature In report, including the report id 0. Let me try other os as well.
The Test GUI indeed has an issue to cut the feature in report by one byte. But the question is that should we report reading 3 bytes or 2 bytes? I think we probably need to report reading 3 bytes, including the report id 0. In that case the GUI will work fine for the reading of feature report.
@todbot In the end I think hidapitester is good.
The issue is probably for feature report under Windows. Shall we report one more byte so that data will not be truncated? Or shall we discard the first byte (report id 0) to be consistent with the input report under Windows and other OS (edit: this may not be correct, please refer to the comments below)?
Now I start to question the following commit which I proposed in #232 with regard to feature report. It may be correct when the report id is not zero but may not be correct when the report id is zero. It seems to me for Windows, we may need to read one more byte when the report id is zero.
github.com/libusb/hidapi@6fcb0bb228@Youw : please take a look as well for the feature report. Thanks.
Ref:
https://github.com/libusb/hidapi/issues/229#issuecomment-810780640
https://github.com/liquidctl/liquidctl/issues/312
My recommendation is to discard the report id 0 for feature report under Windows, to be consistent with input report handing under Windows, and also other OS.
Edit: this may not be correct. From the Linux hidapitester output, indeed there is a difference in dealing with input report the feature report. Not so sure if this is because of API difference or real different on the wire.
Output under Linux:
Output under macOS (Mac Mini M1, macOS Big Sur ARM64), same as Linux.
Linux test gui is consistent with hidapitester

Hopefully other Windows users can chime in and test latest git of hidapi to see if there is a real issue for the feature report or not.
Just tried hidapitester with hidapi-0.10.1 release and hidapi git head, with regard to input report, the result is the same since it is using hid_read_timeout(). So #232 does not matter in that case.
https://github.com/todbot/hidapitester/blob/master/hidapitester.c#L379
With regard to feature report, then the result will be different as it uses hid_get_feature_report(). So commit
github.com/libusb/hidapi@6fcb0bb228does matter for getting the feature report. In this particular case without report id (report id zero), it seems to me the commit is not correct.https://github.com/todbot/hidapitester/blob/master/hidapitester.c#L403
For those with report id, commit
github.com/libusb/hidapi@6fcb0bb228seems to be correct.Here is a quick hack of hidapitester with libusb backend (https://github.com/todbot/hidapitester/issues/8)
With patched libusb-1.0.dll (https://github.com/libusb/libusb/pull/986), it works fine.
hidapitester_mingw64_libusb.zip
It also works fine with devices with report ids (my mod FW of the above generic hid example from Jan Axelson).
All in all, hidapitester is okay. But we may need to fix hidapi under Windows, for reading of feature report. Therefore I have created an issue #328.
I will close this as hidapitester is already mentioned in hidapi README.md.
https://github.com/libusb/hidapi/blob/master/README.md