include stdio define DEVICE dev ttyS0 ifdef DEBUG define PDEBUG printf

 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
#include <stdio.h>
#define DEVICE "/dev/ttyS0"
#ifdef DEBUG
#define PDEBUG printf
#else
#define PDEBUG(x,...)
#endif
int main(void) {
char buf[1];
FILE *fd = fopen(DEVICE, "r+");
int i = fread(buf, 1, 1, fd);
if (i) {
PDEBUG("buf = 0x%x\n", buf[0]);
buf[0] = ~buf[0];
fwrite(buf, 1, 1, fd);
}
else {
PDEBUG("nothing\n");
}
fclose(fd);
return 0;
}