-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibusb.cpp
More file actions
57 lines (50 loc) · 1.26 KB
/
libusb.cpp
File metadata and controls
57 lines (50 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include "libusb.h"
#include<iostream>
using namespace std;
static void print_devs(libusb_device **devs)
{
libusb_device *dev;
int i = 0, j = 0;
uint8_t path[8];
while ((dev = devs[i++]) != NULL) {
struct libusb_device_descriptor desc;
int r = libusb_get_device_descriptor(dev, &desc);
if (r < 0) {
fprintf(stderr, "failed to get device descriptor");
return;
}
printf("%04x:%04x (bus %d, device %d)",
desc.idVendor, desc.idProduct,
libusb_get_bus_number(dev), libusb_get_device_address(dev));
r = libusb_get_port_numbers(dev, path, sizeof(path));
if (r > 0) {
printf(" path: %d", path[0]);
for (j = 1; j < r; j++)
printf(".%d", path[j]);
}
printf("\n");
}
}
int main(void)
{
libusb_device **devs;
int r;
ssize_t cnt;
cout << __FUNCTION__<<"(), " << __LINE__ << endl;
r = libusb_init(NULL);
cout << __FUNCTION__<<"(), " << __LINE__ << endl;
if(r < 0){
cout << __FUNCTION__<<"(), " << __LINE__ << endl;
return r;
}
cnt = libusb_get_device_list(NULL, &devs);
if(cnt < 0){
cout << __FUNCTION__<<"(), " << __LINE__ << endl;
return (int) cnt;
}
print_devs(devs);
libusb_free_device_list(devs, 1);
libusb_exit(NULL);
return 0;
}