Reputation: 63
Here's my C code:
int main()
{
struct usb_bus *busses, *bus;
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
for (bus = busses; bus; bus = bus->next)
{
struct usb_device *dev;
for (dev = bus->devices; dev; dev = dev->next)
{
struct usb_device_descriptor *desc;
desc = &(dev->descriptor);
printf("idVendor/idProduct ID: %2.2x : %2.2x\n",desc->idVendor,desc->idProduct);
if ((desc->idVendor == 0x2232) && (desc->idProduct == 0x6001))
{
printf("iManafacturer/iProduct ID: %04x :%04x \n",desc->iManufacturer,desc->iProduct);
//return dev;
}
}
}
system("pause");
return NULL;
}
After I complied the code (compile result), I can not get the iManufacturer number just like USBView result. I do not know how to get the iManufacturer (for example, NMGAAI00010200144W11111) like the USBView show.
How can I do this?
Upvotes: 4
Views: 6341
Reputation: 2917
The iManufacturer
field of the device descriptor is the index of the manufacturer string descriptor. The string is optional, an index of 0 means there is no string.
If you want the string, you can use static int libusb_get_string_descriptor()
to get the string in unicode in any available language or the convenience method int libusb_get_string_descriptor_ascii()
that gives you a C "string" in the first available language. You need a libusb_device_handle
first.
Quick ugly example without any error checking :
libusb_open(dev, &dev_handle);
unsigned char manufacturer[200];
libusb_get_string_descriptor_ascii(dev_handle, desc->iManufacturer,
manufacturer,200);
printf("%s \n", manufacturer);
In 0.1, there are similar methods usb_get_string()
and usb_get_string_simple()
.
Upvotes: 6