Commit | Line | Data |
---|---|---|
81e70d48 PH |
1 | |
2 | #include <stdio.h> | |
3 | #include <fcntl.h> | |
4 | #include <stdlib.h> | |
5 | #include <stdint.h> | |
6 | ||
7 | int main (int argc, char ** args){ | |
8 | int fd; | |
9 | ||
10 | fd=open("/dev/ttyUSB0", O_RDWR); | |
11 | if (fd<0) { | |
12 | perror("While opening port"); | |
13 | exit(2); | |
14 | } | |
15 | ||
16 | int i=0; | |
17 | for (i=0; i<0x1000;i++){ | |
18 | char t1,t2,t3; | |
19 | t1=i&0xff; | |
20 | int ret=write(fd,&t1,1); | |
21 | if (ret!=1) { | |
22 | perror("While writing to port"); | |
23 | exit(2); | |
24 | } | |
25 | if (i%77==0) usleep(5000); | |
26 | if (i%355==0) usleep(50000); | |
27 | ret=read(fd,&t2,1); | |
28 | if (ret!=1) { | |
29 | perror("While reading from port"); | |
30 | exit(2); | |
31 | } | |
32 | ret=read(fd,&t3,1); | |
33 | if (ret!=1) { | |
34 | perror("While reading from port"); | |
35 | exit(2); | |
36 | } | |
37 | ||
38 | t3=~t3; | |
39 | if ((t1!=t2)||(t3!=t1)){ | |
40 | fprintf(stderr,"Data mismatch!!!\n"); | |
41 | fprintf(stderr,"T1: %03o T2: %03o T3: %03o\n",t1,t2,t3); | |
42 | exit(3); | |
43 | } | |
44 | } | |
45 | ||
46 | printf("Success.\n"); | |
47 | ||
48 | return 0; | |
49 | } |