OpenUSB Developers Guide
Prev |  | Next

# `openusb_get_devids_by_bus, openusb_get_devids_by_vendor, openusb_get_devids_by_class, openusb_free_devid_list`

## Name

`openusb_get_devids_by_bus, openusb_get_devids_by_vendor, openusb_get_devids_by_class, openusb_free_devid_list` -- Return all devids matching a pattern, Free returned devids

## Synopsis

``uint32_t openusb_get_devids_by_bus`(openusb_handle_t handle , openusb_busid_t busid , openusb_devid_t **devids , uint32_t *num_devids );`

``uint32_t openusb_get_devids_by_vendor`(openusb_handle_t handle , int32_t vendor , int32_t product , openusb_devid_t **devids , uint32_t *num_devids );`

``uint32_t openusb_get_devids_by_class`(openusb_handle_t handle , int16_t devclass, int16_t subclass, int16_t protocol, openusb_devid_t **devids , uint32_t *num_devids );`

``void openusb_free_devid_list`(openusb_devid_t * devids);`

## Parameters

`handle` - Libusb handle returned in openusb_init().

`busid` - Which bus (0 for all busses).

`devids` - Pointer to address of the devid list, allocated by openusb.

`num_devids` - Number of device ids by this search/match.

`vendor` - Vendor ID (0 - 0xFFFF, -1 for all).

`product` - Product ID (0 - 0xFFFF, -1 for all).

`class` - Class (0 - 0xFF, -1 for all).

`subclass` - Subclass (0 - 0xFF, -1 for all).

`protocol` - Protocol (0 - 0xFF, -1 for all).

## Description

These functions are used to get/free device IDs of those devices that an application is interested in. Application depends on these devids to do any other operation on a device. For example, when application wants to transfer data to a device, it has to specify the devid got here to call corresponding openusb functions to open.

`openusb_get_devids_by_bus()` returns all the ids of devices on a bus. If `busid` is 0, it will return all `devids` in the system. The returned devids are stored in `devids`. The number of devids is in `num_devids` .

`openusb_get_devids_by_vendor()` returns all devids of devices that match specific VID and PID. If `vendor` = -1, it will match any vendor's device. If `product` = -1, it will match any devices of a vendor. If both are -1, it will match any devices of any vendor.

`openusb_get_devids_by_class()` returns all devids of devices that match specific `class, subclass or protocol`. This function first uses application supplied class, subclass and protocol to match their counterpart in Device Descriptor of a device. If they don't match, then this function will try to match class, subclass and protocol to their counterparts in invidual Interface Descriptors of a device. If an argument is -1, it means to match any class, subclass or protocol.

`openusb_free_devid_list()` frees `devids` returned in above interfaces.

## Return Value

openusb_get_devids_by_bus(), openusb_get_devids_by_vendor(), openusb_get_devids_by_class() may have the following return values:

OPENUSB_SUCCESS - Success.

OPENUSB_NO_RESOURCES - Memory allocation failure.

OPENUSB_BADARG - Invalid argument. devids or num_devids is NULL; busid is invalid; vendor or product is out of range; class, subclass or product is out of range.

OPENUSB_NULL_LIST - The devids list is empty.

OPENUSB_INVALID_HANDLE - Libusb handle is invalid.

## See Also

`openusb_init, openusb_fini`

Prev | Home | Next
`openusb_get_busid_list, openusb_free_busid_list` | Up | `openusb_get_device_data,openusb_free_device_data`