-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
58 lines (52 loc) · 1.2 KB
/
main.cpp
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
58
#include<cstdio>
#include<libusb.h>
// TODO: Change these values to those from the real DAQ
#define DAQ_VID 0x3923
#define DAQ_PID 0x717a
void printdev(libusb_device *dev);
int main()
{
libusb_device **devs;
libusb_context *ctx = NULL;
int r;
ssize_t cnt;
r = libusb_init(&ctx);
if (r<0)
{
fprintf(stderr,"Initialization Error: %d\n",r);
return 1;
}
libusb_set_debug(ctx,3);
libusb_device_handle *dev;
dev = libusb_open_device_with_vid_pid(ctx,DAQ_VID,DAQ_PID);
if (dev<=0)
{
fprintf(stderr,"Error opening device: %d\n",dev);
return 1;
}
printf("DAQ Found!\n");
r=libusb_kernel_driver_active(dev,1);
printf("Kernel Driver Active: ");
if (r==1) {
printf("Yes\n");
} else if (r==0) {
printf("No\n");
} else {
printf("Error: %d\n",r);
}
r=libusb_claim_interface(dev,1);
if (r!=0) {
printf("Error claiming interface: %d\n", r);
return 1;
}
unsigned char test[] = {
0x00, 0x01, 0x00, 0x14, 0x00, 0x10, 0x01, 0x14, 0x02, 0x04, 0x00,
0x00, 0x00, 0x00, 0x01, 0xd2, 0x00, 0x01, 0x00, 0x00
};
int transfered;
r=libusb_bulk_transfer(dev,0x01,test,20,&transfered,100);
printf("%d\n",r);
libusb_close(dev);
libusb_exit(ctx);
return 0;
}