What is the best usb library to communicate with usb HID devices on Windows?

风流意气都作罢 提交于 2019-12-03 18:36:04

问题


The library should;

-Be easy to use and few lines of client code should accomplish much
-Be as platform independent as possible. (In case of future ports to other platforms)
-Have C++ bindings.
-Be mature and stable

I would also like to be notified of most HID events through callbacks.

I have considered the following alternatives:

*libhid - (Unfortunately?) this is GPL and cannot be used in my application.
*WDK - Seems to be a bit low-level for my use. I don`t need that kind of control
*atusbhid - This has an appropriate level of abstraction but is firmly tied to the windows messaging loop

Do any of you have any other alternatives to offer?


回答1:


Take a look at hidapi: it is C, which answers the C++ bindings question (effectively :)), is cross platform and has a very permissive license. Doesn't appear to have the callbacks, but...




回答2:


If libhid works for you, then perhaps the thing to do would be to write an app (which you would GPL), which uses libhid to talk to devices, then provides whatever you need via a TCP connection. Your real app would connect via TCP to do what it needs. This would obviously be a massive performance hit.

This app would effectively be a 'shim' between libhid and your app. In this case, the shim would exist for legal, not technical reasons.

I'm not saying it's a good idea, just that it's an idea.




回答3:


HIDmaker software suite from Trace systems is an option.

Pros: - Easy to use (Excelent for learning how to program for USB HID) - Generates working applications source code in a various project formats (Visual Studio, Borland) - Generates stable example code for both host and device (stable in my experience) - High performance (if HID can even be said to have high performance in the first place)

Cons: - Only works on Microsoft Windows - Uses it's own USB library I think (ActiveX)




回答4:


Consider rolling your own. You'll have total control over the interface, the level of platform independence, and such. Even though a project is GPL, you can use it as a recipe for your own, and as a testbed to find issues with your own.




回答5:


There are several USB HID Host drivers for Windows. An easy to use Dynamic Link Library is from http://embedded24.net. There are also several example applications included for Visual Studio 2010 (C++, C# and VB).




回答6:


Look at this code:

http://geekswithblogs.net/tamir/archive/2008/12/30/read-and-use-fm-radio-or-any-other-usb-hid.aspx

It gives you some simple classes to talk to a HID device. What it boils down to is, get the alias for the device (something like \?\HID#Vid_nnnn&Pid_nnn#.......) and use CreateFile to open it. You can get the device's alias under HKML\SYSTEM\CCS\Control\DeviceClasses{4d1e55...}\

The Vid and Pid are the vendor ID and product ID of the device (check Device Manager).



来源:https://stackoverflow.com/questions/280199/what-is-the-best-usb-library-to-communicate-with-usb-hid-devices-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!