Linux HID APIS similar to Windows HID APIs [closed

2019-09-05 21:22发布

I am looking for corresponding Linux HID APIs similar to what is mentioned on Microsoft this page :

http://msdn.microsoft.com/en-us/library/windows/hardware/jj126202(v=vs.85).aspx

Basically functions corresponding to DataMovement :

Data Movement
The following list identifies HID API that an application can use to move data back and forth  between the app and a selected device.

HidD_GetInputReport
HidD_SetFeature
HidD_SetOutputReport
ReadFile
WriteFile 

I have two directions currently to :

-> Install the wine framework and try use the Windows Application(utilizing HID Apis)

-> Second to Use the Corresponding Linux HID Apis(dark area for me)

Thanks,

标签: linux api hid
1条回答
Deceive 欺骗
2楼-- · 2019-09-05 22:14

A cross-platform HID API library is HIDAPI (under the hood, it uses the ReadFile/WriteFile stuff for Windows and libusb for Linux). I have never used it so I cannot vouch for it.

If all you need is SetReport and GetReport, then it may be easier to operate on hidraw devices in Linux. I use this technique for ltunify. You can discover which /dev/hidrawX device belongs to a device by querying sysfs (example).

Once you have a device (say, /dev/hidraw0), then you can open it for reading and writing and use the POSIX read() and write() functions. You may hit a permissions issue, but that is solvable by changing the permissions of the device, either manually (setfacl -m u:$USER:rw /dev/hidraw0) or with a udev rule such as 42-logitech-unify-permissions.rules.

Since you need to support both Windows and Linux platforms, I think that you are better off with using the HIDAPI library mentioned before.

查看更多
登录 后发表回答