55 struct termio tty_set;
58 if ( (tty_fd = open(p_tty_name, O_RDWR | O_NOCTTY | O_NDELAY)) < 0 )
60 printf(
"ERROR: Couldn't open port %s!\n", p_tty_name);
65 if (ioctl(tty_fd, TCGETA, &tty_set ) == -1 )
67 printf(
"ERROR: ioctl() failed to read settings!\n");
72 tty_set.c_cflag = (B115200 | CS8 | CLOCAL | CREAD);
73 tty_set.c_iflag = IXOFF;
76 tty_set.c_cc[VTIME] = 20;
77 tty_set.c_cc[VMIN] = 0;
79 if (ioctl(tty_fd, TCSETAW, &tty_set ) == -1 )
81 printf(
"ERROR: ioctl() failed to set settings!\n");
106 struct termio tty_set;
108 if (ioctl(tty_fd, TCGETA, &tty_set ) == -1 )
110 printf(
"ERROR: ioctl() failed to read settings!\n");
115 tty_set.c_cflag &= ~CBAUD;
116 tty_set.c_cflag |= speed;
118 if (ioctl(tty_fd, TCSETAW, &tty_set ) == -1 )
120 printf(
"ERROR: ioctl() failed to set settings!\n");
147 if (( bytes_out = write(tty_fd, p_buffer, nb_byte)) < nb_byte)
149 printf(
"ERROR: write() failed!\n");
184 while (tries < 2 && !ready)
190 FD_SET(tty_fd, &fds);
191 if (select(FD_SETSIZE, &fds, 0, 0, &tz) > 0)
193 qu_new = read(tty_fd, &p_buffer[bytes_read], (nb_bytes_max - bytes_read));
195 bytes_read += qu_new;
198 ready = (bytes_read == nb_bytes_max);
244 while (max_time_secs--)
250 FD_SET(tty_fd, &fds);
252 if (select(FD_SETSIZE, &fds, 0, 0, &tz) > 0)
277 if (-1 == tcflush (tty_fd, TCIFLUSH))
long empty_serial(int tty_fd)
long write_serial(int tty_fd, unsigned char *p_buffer, long nb_byte)
void close_serial(int tty_fd)
long change_baud_serial(int tty_fd, speed_t speed)
long wait_for_serial(int tty_fd, long max_time_secs)
int open_serial(const char *p_tty_name)
long read_serial(int tty_fd, unsigned char *p_buffer, long nb_bytes_max)