Blame view

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