5 #include <sys/select.h>
21 unsigned char wbuff, rbuff;
23 struct timeval timeout_tv;
26 tcflush(fd, TCIOFLUSH);
28 if (tcgetattr(fd, &term) < 0) {
32 term.c_cflag &= ~CSIZE | CS8;
33 cfsetispeed(&term, B9600);
34 cfsetospeed(&term, B9600);
35 tcsetattr(fd, TCSANOW, &term);
39 wbytes = write(fd, &wbuff, 1);
45 timeout_tv.tv_usec = 0;
51 if (select(fd + 1, &readset, NULL, NULL, &timeout_tv) > 0) {
53 if (FD_ISSET(fd, &readset)) {
54 int rbytes = read(fd, &rbuff, 1);
78 term.c_cflag &= ~CSIZE | CS6;
79 cfsetispeed(&term, B115200);
80 cfsetospeed(&term, B115200);
82 tcsetattr(fd, TCSANOW, &term);
91 unsigned char rbuff, i;
92 size_t remaining, rbytes;
94 struct timeval timeout_tv;
96 tcflush(fd, TCIOFLUSH);
98 for (i = 0; i < 8; i++) {
99 buf[i] = (wbuff & (1 << (i & 0x7))) ? 0xff : 0x00;
101 wbytes = write(fd, buf, 8);
107 timeout_tv.tv_usec = 0;
111 FD_SET(fd, &readset);
115 while (remaining > 0) {
117 if (select(fd + 1, &readset, NULL, NULL, &timeout_tv) > 0) {
119 if (FD_ISSET(fd, &readset)) {
120 rbytes = read(fd, &buf, remaining);
121 for (i = 0; i < rbytes; i++) {
123 rbuff |= (buf[i] & 0x01) ? 0x80 : 0x00;
152 return (stat(filename, &st) == 0);
170 fd = open(serial_port, O_RDWR);
176 memset(&term, 0,
sizeof(term));
179 term.c_cc[VTIME] = 0;
180 term.c_cflag |= CS6 | CREAD | HUPCL | CLOCAL;
182 cfsetispeed(&term, B115200);
183 cfsetospeed(&term, B115200);
185 if (tcsetattr(fd, TCSANOW, &term) < 0) {
191 tcflush(fd, TCIOFLUSH);
unsigned char owRead(int fd)
int owOpen(const char *serial_port)
static int file_exists(const char *filename)
static unsigned char owWriteByte(int fd, unsigned char wbuff)
int owWrite(int fd, unsigned char wbuff)