简体   繁体   English

从USB获取设备名称

[英]Get device name from usb

lsusb command lsusb命令

i want to get device name like on lsusb. 我想获得像lsusb一样的设备名称。 I found this code and i tried its all descriptor parameters.Is there any way to get device name like on picture like Log. 我找到了这段代码,并尝试了其所有描述符参数,是否有任何方法可以获取设备名称,如Log之类的图片。 Opt. 选择。 Gam. Mouse 老鼠

#include <stdio.h>
#include <usb.h>
main(){
    struct usb_bus *bus;
    struct usb_device *dev;
    usb_init();
    usb_find_busses();
    usb_find_devices();
    for (bus = usb_busses; bus; bus = bus->next)
        for (dev = bus->devices; dev; dev = dev->next){
            printf("Trying device %s/%s\n", bus->dirname, dev->filename);
            printf("\tID_VENDOR = 0x%04x\n", dev->descriptor.idVendor);
            printf("\tID_PRODUCT = 0x%04x\n", dev->descriptor.idProduct);
        }
}

the poiter for you is look into libusb library. 给您的支持者是libusb库。

starting with libusb_get_device_list which Returns a list of USB devices currently attached to the system. 以libusb_get_device_list开头,它返回当前连接到系统的USB设备的列表。 http://libusb.sourceforge.net/api-1.0/group__dev.html#gac0fe4b65914c5ed036e6cbec61cb0b97 http://libusb.sourceforge.net/api-1.0/group__dev.html#gac0fe4b65914c5ed036e6cbec61cb0b97

you can take it from there. 你可以从那里拿走。

if you want other way reading /sys/bus/usb/devices directory and read valid devices. 如果您想以其他方式读取/ sys / bus / usb / devices目录并读取有效的设备。 except root hub or other hubs. 根集线器或其他集线器除外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM