[libhid-discuss] finding multile devices

Charles Lepple clepple at ghz.cc
Sat Jan 12 15:32:23 UTC 2008


On Jan 12, 2008, at 7:34 AM, Warren Jasper wrote:

> I am writing a API to interface to data acquisition HID devices.  I  
> have no problem interfacing to a single device with a unique Vendor  
> ID and Product ID with multiple interfaces.  I am following the  
> example in the test program example to get the HIDInterface handle  
> for the device.
>
> My question is this.  How do I handle multiple devices?  This  
> question has probably come up before, but searching the net I could  
> not find it.  I need a way to scan all the buses for ALL the  
> devices that match a unique Product ID and Vendor ID and return a  
> pointer.  Of course each of the devices could have multiple USB  
> interfaces, which could contain multiple endpoints.


I think the original plan for multiple device support was to make use  
of the serial number. In many cases with multiple identical devices,  
you need to know which device is which, and having a serial number  
would simplify this greatly. Otherwise, plugging in the devices in a  
different order would mean that the first device opened would be a  
different physical device.

There is a match_serial_number() function in the test program that  
shows how you could do this. However, I realize that most devices  
don't have a serial number. You could use the hid_is_opened()  
function along with a custom matcher function and a list of already- 
opened interfaces.

You're right in that we should not try to open a device if it has  
been opened already; however, hid_is_opened only checks to see if a  
handle was opened in the current process. There is no easy way to  
tell (short of trying to open a device and failing) whether another  
process using libhid has opened the device/interface.

-- 
Charles Lepple




More information about the libhid-discuss mailing list