LibUSB????????,?????USB?????
- ??LibUSB?:
?Debian?Ubuntu???,??????????LibUSB?:
sudo apt-get install libusb-1.0-0-dev
?Fedora?Red Hat???,??????????LibUSB?:
sudo yum install libusb-devel
- ???????LibUSB??:
??????list_devices.c
???,???????:
#include#include #include int main() { libusb_context *ctx = NULL; libusb_device **devs = NULL; ssize_t cnt; int r, i; r = libusb_init(&ctx); if (r < 0) { fprintf(stderr, "Failed to initialize libusb\n"); exit(1); } cnt = libusb_get_device_list(ctx, &devs); if (cnt < 0) { fprintf(stderr, "Failed to get device list\n"); libusb_exit(ctx); exit(1); } printf("Found %ld devices\n", cnt); for (i = 0; i < cnt; i++) { struct libusb_device_descriptor desc; r = libusb_get_device_descriptor(devs[i], &desc); if (r < 0) { fprintf(stderr, "Failed to get device descriptor\n"); continue; } printf("Device %d: ID x:x\n", i, desc.idVendor, desc.idProduct); } libusb_free_device_list(devs, 1); libusb_exit(ctx); return 0; }
- ????:
????,?????list_devices.c
?????,????????:
gcc -o list_devices list_devices.c -lusb-1.0
?????????????list_devices
???????
- ????:
?????,??root??,????USB???????????????:
sudo ./list_devices
??????????????USB?????????????ID???ID?
??????????,LibUSB????????,????????????????????????LibUSB???,???????:http://libusb.info/