? Linux ??? libusb ??????,????????:
-
?? libusb ?:
??,??????????? libusb ??????,????????(? apt?yum ? pacman)???????,??? Debian ????,??????????:
sudo apt-get update sudo apt-get install libusb-1.0-0-dev
-
????:
??????
usb_example.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; } ???????????????? USB ?????????? ID?
-
????:
??????????:
gcc -o usb_example usb_example.c -lusb-1.0
-
????:
??????????:
./usb_example
?????????????? USB ?????????? ID?
-
?????:
????????,?????????????? ID???,????? libusb ?????(?
libusb_open()
?libusb_claim_interface()
?libusb_bulk_transfer()
?)????????????????????????
??:??? libusb ???????,????????????????????????? plugdev
???????:
sudo usermod -a -G plugdev $USER
??,??????????????