Commit b79c0c437735df2ca5a194a1ef0bf6608573d0f5

Authored by gperson
1 parent 18fb979a

ajout de code,Verifications de compilation

Showing 1 changed file with 39 additions and 2 deletions   Show diff stats
src/GetUsbInfos.c
1 1 #include <stdio.h>
2 2 #include <libusb-1.0/libusb.h>
  3 +#include <stdlib.h>
  4 +
  5 +
  6 +
  7 +
  8 +
3 9  
4 10 int main(){
5   - return 0;
6   -}
7 11  
8 12  
9 13  
10 14  
  15 +
  16 +
  17 +//initiate the usb thing
  18 +
  19 + libusb_context *context;
  20 + int status=libusb_init(&context);
  21 + if(status!=0) {perror("libusb_init"); exit(-1);}
  22 + /* ... some code ... */
  23 + libusb_exit(context);
  24 +
  25 +// actually enumerates all the usb and gives some infos abot the usb things
  26 +
  27 + libusb_device **list;
  28 + ssize_t count=libusb_get_device_list(context,&list);
  29 + if(count<0) {perror("libusb_get_device_list"); exit(-1);}
  30 + ssize_t i=0;
  31 + for(i=0;i<count;i++){
  32 + libusb_device *device=list[i];
  33 + struct libusb_device_descriptor desc;
  34 +
  35 + int status=libusb_get_device_descriptor(device,&desc);
  36 + if(status!=0) continue;
  37 +
  38 + uint8_t bus=libusb_get_bus_number(device);
  39 + uint8_t address=libusb_get_device_address(device);
  40 +
  41 + printf("Device Found @ (Bus:Address) %d:%d\n",bus,address);
  42 + printf("Vendor ID 0x0%x\n",desc.idVendor);
  43 + printf("Product ID 0x0%x\n",desc.idProduct);
  44 + }
  45 + libusb_free_device_list(list,1);
  46 + return 0;
  47 +}
... ...