I have created a program using libusb. I doubt if the output is correct because all entries show the same seller and product ID, the following is the code:
#include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Libusb-1.0 / libusb.h & gt; Zero print_devices (libusb_device * dev) {struct libusb_device_descriptor desc; Struct libusb_config_descriptor * config; Const struct libusb_interface * difference; Const. Composition libusb_interface_descriptor * interdesc; Const. Composition libusb_endpoint_descriptor * endpointdesc; Int rate; Int i, j, k; If (rate at lieutenant; 0) {fprintf (stderr, "Error obtaining device descriptor \ n"); Return; } Printf ("The number of possible configs is% d \ n", desc.bNumConfigurations); Printf ("Seller:% d \ n", desc.idVendor); Printf ("Product ID:% d \ n", desc.idProduct); Libusb_get_config_descriptor (dev, 0, and config); Printf ("Interface:% d \ n", config- & gt; bNumInterfaces); Printf ("\ n \ n"); } Int main (int argc, char * argv []) {libusb_device ** devs; Libusb_context * context = NULL; Size_t list; Size_t i; Int rate, temporary; Rate = libusb_init (& context); If (Rate End Lt; 0) {Explanation ("LibSub_Init"); Exit (1); } List = libusb_get_device_list (references, & devs); If (list & lt; 0) {fprintf (stderr, "error in getting device list \ n"); Libusb_free_device_list (devs, 1); Libusb_exit (reference); Exit (1); } Temp = (int) list; Printf ("\ n% d device found \ n \ n", temp); {// print device print_devices (devs [i]) for (i = 0; i & lt; temp; i ++); } Libusb_free_device_list (devs, 1); Libusb_exit (reference); Return 0; }
And it is my output:
Experience @ experience- Inspiron-3421: ~ / Desktop / usb $ ./usbtest 9 devices found number 0 product ID: possible configuration 103 vendor 0 interface: 1 number of possible configurations 103 vendors: 0 product ID: 0 interface: 0 product ID :: 0 interface: 2 number of possible configurations 1 number of possible configurations 103 vendors Has 0 Product ID: 103 Vendor is 0 Interface: 4 The number of possible configurations is 103 Vendor: 0 product ID: 0 interface: 0 product ID :: 0 Interface: 1 Number of possible configuration 103 1 is the number of possible configurations 103 vendors Seller: 0 product ID: 0 interface: 0 product ID :: 1 Number of possible configurations 103 vendor interface 0: 0 product ID :: 0 interface: 1 number 103 vendors of possible configurations 1
this is what shows the lsusb:
Experience @ Experience - Inspiron-3421: ~ / Desktop / usb $ lsusb Bus 002 Device 002: ID 8087: 0024 Ntel Corp. Integrated Rate Matching Hub Bus 002 Device 001: ID Ld6b: 0002 Lin UX Foundation 2.0 root hub Bus 001 Device 004: ID 064e: 812c Suyin Corp. Bus 001 Device 007: ID 0a5c: 2ld7 Broadcom Corporation BCM43142 Bluetooth 4.0 Bus 001 Device 003 : ID 0bda: 0129 Realtek Semiconductor Corp. RTS5129 card Reader controller Bus 001 device 002: ID 8087: 0024 Intel Corp. integrated rate matching hub Bus 001 device 001: ID Ld6b: 0002 Linux Foundation 2.0 root hub Bus 004 device 001: ID Ld6b: 0003 Linux Foundation Not 3.0 root hub Bus 003 Device 001: ID 1D 6B: 0002 Linux Foundation 2.0 root hub
Need help finding errors (if any).
A line must be hidden from somewhere by mistake ... I recommend that you add the following line Otherwise ret
is initial:
int retired; Int i, j, k; Rate = libusb_get_device_descriptor (dev, & desc); // this line! If (rate at lieutenant; 0) {fprintf (stderr, "Error obtaining device descriptor \ n"); Return; } idvendor
to print the output to lsusb
with one of the % x
Change the code> and using the idProduct
hexadecimal format. printf ("vendor:% x \ n", desc.idVendor); Printf ("Product ID:% x \ n", desc.idProduct);
The following question was helpful to find the missing line. And it helped me add libusb
, it recommends compiling it with gcc main.c -o main -lusb-1.0
.
No comments:
Post a Comment