-
Notifications
You must be signed in to change notification settings - Fork 474
Hello,
The title is the question. I compiled hidtest.exe and it can enumerate devices. I see my keyboard there and I placed its ID to the hid_open function. It then provides some details about the device, but some functions fail:
Unable to send a feature report.
Unable to get a feature report.
Incorrect function.Unable to write()
Error: Incorrect function.
Unable to write() (2)
I heard that Windows allegedly has some limitations for HID keyboards and mices, but this project can work with my keyboard. Thus, it should be possible.
All reactions
I see 3 or 4 entries for my keyboard
Windows creates a separate logical HID device for each (top-lelvel) usage_page/usage pair (see official doc: https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/top-level-collections).
The hid_open function has optional 'serial' parameter
hid_open is not sufficient for this purpose. You need to use hid_enumerate, and find a specific device with specific VID+PID+SerialNumber+USAGE+USAGE_PAGE.
E.g.: HID_USAGE_PAGE_GENERIC/(HID_USAGE_GENERIC_MOUSE|HID_USAGE_GENERIC_KEYBOARD) is never allowed direct access using HIDAPI on Windows. That is an OS limitation.
By opening first device (usage_page/usage) there is a high chance you get the Keyboard ...
Replies: 4 comments 4 replies
P.S. In the enumerated list I see 3 or 4 entries for my keyboard. Does it matter? I mean if I need somehow to switch between them? If yes, then how can I do that? The hid_open function has optional 'serial' parameter, but it's the same for all entries related to the keyboard.
@CalcProgrammer1, if I'm not mistaken, you had similar problem in past and you solved it by changing the Interface, right?
All reactions
I see 3 or 4 entries for my keyboard
Windows creates a separate logical HID device for each (top-lelvel) usage_page/usage pair (see official doc: https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/top-level-collections).
The hid_open function has optional 'serial' parameter
hid_open is not sufficient for this purpose. You need to use hid_enumerate, and find a specific device with specific VID+PID+SerialNumber+USAGE+USAGE_PAGE.
E.g.: HID_USAGE_PAGE_GENERIC/(HID_USAGE_GENERIC_MOUSE|HID_USAGE_GENERIC_KEYBOARD) is never allowed direct access using HIDAPI on Windows. That is an OS limitation.
By opening first device (usage_page/usage) there is a high chance you get the Keyboard collection and not the RGB, that's why you don't have access to read or write.
but this project can work with my keyboard
It searches for a specific usage_page/usage for each known device: 1, 2.
All reactions
-
🎉 1
@Youw, thanks a lot for the explanation!
So, what should I do:
- Find the correct usage_page+usage // I've found
- Enumerate devices and find the one that matches all there parameters
- Remember the path
- Open device with that path and work with it in further ( handle = hid_open_path(cur_dev->path); )
Correct? Is it the simplest way?
I did so and see that keyboard can react on my hid_write. Just want to make sure I should use hid_open_path.
All reactions
Yes, everything is correct.
There is no simpler way.
All reactions
The last, I hope, question. The device still doesn't answer to hid_send_feature_report and hid_get_feature_report, but I'm able now to control RGB zones via hid_write. Actually, that's my goal. Just curious if the feature report should work in that case or it depends on the device?
All reactions
hid_write sends the output report. It is not the same as feature reports.
Input, output or feature reports - that's more like a "transport" defined by HID standard.
But which specific reports are supported by a specific device - that's, of course, device-specific.
All reactions
@xcme ,
It looks you can control RGB by hid_write. would you mind introduce how is it work? many thanks.
All reactions
@xcme , It looks you can control RGB by hid_write. would you mind introduce how is it work? many thanks.
Hello @JordanChiang,
Yes, it works for me. I use that tool to send the data that I prepare in a batch script. The main thing here is to know what to send exactly. I found a project on GitHub that has data for my keyboard, so I took them and created that simple batch script.
So, if you know the data (any working code for your device would help here), then you can do PoC:
- Download hidapitester.exe and issue:
hidapitester --list - Found your device, remember the "vid" and then request more details for that "vid":
hidapitester --vidpid XXXX --list-detail - According to the code example you have, pick up the right "usagePage" and "usage". Now you have all the needed parameters: "vid", "pid", "usagePage" and "usage".
- Then prepare your data. For my device the data has "controls" (4 constant bytes), "zone" (1 byte), "rgbmode" (1 byte) and "r", "g" and "b" values (1 byte for each). Each byte has to be represented in decimal form and separated by comma (see hidapitester usage examples).
- Send your data by command like this:
hidapitester.exe --vidpid %vid%:%pid% --usagePage %usagepage% --usage %usage% --list-detail --open --send-output %data%.
It will show something like:
Opening device, vid/pid:0xXXXX/0xXXXX, usagePage/usage: XXXX/XXXX
Device opened
Writing output report of 64-bytes...wrote 20 bytes:
XX XX XX XX...
XX XX XX XX
Closing device
And the device should react on your command.
Hope it helps.
P.S. If you have come experience with C then it's possible to modify some source example from the hidapitester and it would do the same. It means no batch is needed anymore, only small single "exe" does all the job. I've tried it and it worked for me, but I didn't finish that, because I have lack of knowledge about C.