SLAA453A january 2011 – may 2023
Description
Attempts to locate a device of index deviceIndex within the list of devices on the system that are associated with this VID/PID and serial number. If found, it opens a handle to the device and stores it within the pstrHidDevice structure, and loads the other fields within the structure as well.
To accomplish its goal, HID_Open() needs two additional parameters. One is the totalDevNum, which is the number of HID interfaces on the device described by vid and pid. Usually the developer knows this already. If not, then HID_GetNumOfInterfaces() can be called. Another required parameter is totalSerNum, which is the total number of serial numbers (physical devices) on the system matching this VID/PID.
deviceIndex is a number from 0 to totalDevNum-1. Once vid, pid, and serialNumber are used to filter the Windows HID device list, the list is effectively reduced to HID devices representing HID interfaces contained within a particular physical USB device. All that remains is to select one of those interfaces, and this is what deviceIndex does. The ordering of these HID devices (zero through totalDevNum) is the same as the order in which the HID interfaces were declared in the device's USB descriptors (see Section 3.5).
If the device described by vid and pid has only one HID interface in it, deviceIndex can simply be 0.
The function assumes that this device is in fact an HID device, and not a USB device of another type.
Parameters
strHidDevice* pstrHidDevice | The structure to contain the newly-opened device. |
WORD vid | 16-bit vendor ID of the device to be opened. |
WORD pid | 16-bit product ID of the device to be opened. |
DWORD deviceIndex | The index within the available devices of this VID/PID and serial number. |
char serialNumber[SERNUM_LEN] | Char string of size SERNUM_LEN (40) of the serial number of the device to be found. |
DWORD totalDevNum | The total number of HID interfaces of a the physical device described by this VID/PID and serial number. |
DWORD totalSerNum | The total number of available physical USB devices for this VID/PID |
returns | HID_DEVICE_SUCCESS. The device has been found and opened. |
HID_DEVICE_ALREADY_OPENED. The device has already been opened. | |
HID_DEVICE_NOT_FOUND. No device identified by this VID/PID/index could be located. |