Revision 8c95bbef
Changed read util to flush input and wait for reads to complete
util/read.c | ||
---|---|---|
14 | 14 |
struct termios ios; |
15 | 15 |
bzero(&ios, sizeof(ios)); |
16 | 16 |
ios.c_cflag = B9600 | CS8 | CREAD; |
17 |
tcsetattr(fd, TCSANOW, &ios);
|
|
17 |
tcsetattr(fd, TCSAFLUSH, &ios);
|
|
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
int bswap(int x) { |
... | ... | |
22 | 22 |
| ((x>>8) & 0xff00) | ((x>>24) & 0xff); |
23 | 23 |
} |
24 | 24 |
|
25 |
void read_all(int fd, void *buf, int n) { |
|
26 |
int nread; |
|
27 |
while (n > 0) { |
|
28 |
nread = read(fd, buf, n); |
|
29 |
buf += nread; |
|
30 |
n -= nread; |
|
31 |
usleep(10000); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
25 | 35 |
int main(int argc, char **argv) { |
26 | 36 |
int fd; |
27 | 37 |
char status; |
... | ... | |
30 | 40 |
init_tty(fd); |
31 | 41 |
|
32 | 42 |
while (1) { |
43 |
tcflush(fd, TCIFLUSH); |
|
33 | 44 |
write(fd, read_cmd, sizeof(read_cmd)); |
34 |
read(fd, &status, 1); |
|
45 |
read_all(fd, &status, 1);
|
|
35 | 46 |
if (status == RFID_OK) { |
36 |
read(fd, &serno, 4); |
|
47 |
read_all(fd, &serno, 4);
|
|
37 | 48 |
serno = bswap(serno); |
38 | 49 |
printf("%08x\n", serno); |
39 | 50 |
} else { |
40 | 51 |
printf("error %d\n", (int)(unsigned char)status); |
41 | 52 |
} |
42 |
usleep(100000);
|
|
53 |
usleep(50000);
|
|
43 | 54 |
} |
44 | 55 |
|
45 | 56 |
close(fd); |
Also available in: Unified diff