这是我的C代码:
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;
}
在我编写代码(编译结果)之后,我无法像USBView结果那样获得iManufacturer编号。我不知道如何获得iManufacturer(例如,NMGAAI00010200144W11111),就像USBView节目一样。
我该怎么做?
答案 0 :(得分:3)
设备描述符的iManufacturer
字段是制造商string descriptor的索引。字符串是可选的,索引为0表示没有字符串。
如果你想要字符串,你可以使用static int libusb_get_string_descriptor()
以任何可用语言获取unicode中的字符串,或使用方便方法int libusb_get_string_descriptor_ascii()
为你提供C"字符串"用第一种语言。您首先需要libusb_device_handle
。
没有任何错误检查的快速丑陋示例:
libusb_open(dev, &dev_handle);
unsigned char manufacturer[200];
libusb_get_string_descriptor_ascii(dev_handle, desc->iManufacturer,
manufacturer,200);
printf("%s \n", manufacturer);
0.1,there are similar methods usb_get_string()
and usb_get_string_simple()
。