Mercurial > ~darius > hgwebdir.cgi > tempctrl
comparison testugen.c @ 27:d5a265299a4b
Test programs to talk to the hardware from a PC
author | darius |
---|---|
date | Mon, 10 Apr 2006 17:22:17 +0930 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
26:350e8655cbb7 | 27:d5a265299a4b |
---|---|
1 #include <sys/types.h> | |
2 #include <sys/ioctl.h> | |
3 #include <dev/usb/usb.h> | |
4 #include <sys/errno.h> | |
5 #include <sys/uio.h> | |
6 #include <unistd.h> | |
7 #include <fcntl.h> | |
8 #include <stdio.h> | |
9 | |
10 int | |
11 main(int argc, char **argv) { | |
12 int endpt2fd, i, len; | |
13 char *endpt2name = "/dev/ugen0.2"; | |
14 uint8_t data[256]; | |
15 | |
16 if ((endpt2fd = open(endpt2name, O_RDWR)) == -1) { | |
17 fprintf(stderr, "Unable to open %s: %s\n", endpt2name, strerror(errno)); | |
18 exit(1); | |
19 } | |
20 | |
21 i = 1; | |
22 if (ioctl(endpt2fd, USB_SET_SHORT_XFER, &i) == -1) { | |
23 fprintf(stderr, "Unable to set short xfer on end point 2: %s\n", strerror(errno)); | |
24 exit(1); | |
25 } | |
26 | |
27 while(1) { | |
28 len = read(endpt2fd, data, 256); | |
29 printf("len = %d\n", len); | |
30 if (len == 0) { | |
31 printf("EOF\n"); | |
32 continue; | |
33 } | |
34 if (len == -1) { | |
35 printf("read error: %s\n", strerror(errno)); | |
36 exit(1); | |
37 } | |
38 | |
39 for (i = 0; i < len; i++) | |
40 printf("0x%02x ", data[i]); | |
41 printf("\n"); | |
42 } | |
43 } | |
44 |