56 struct termio tty_set;
59 if ( (tty_fd = open(p_tty_name, O_RDWR |O_NOCTTY)) < 0 )
61 printf(
"ERROR: Couldn't open port %s!\n", p_tty_name);
66 if (ioctl(tty_fd, TCGETA, &tty_set ) == -1 )
68 printf(
"ERROR: ioctl() failed to read settings!\n");
73 tty_set.c_cflag = (B115200 | CS8 | CLOCAL | CREAD);
74 tty_set.c_iflag = IXOFF;
77 tty_set.c_cc[VTIME] = 20;
78 tty_set.c_cc[VMIN] = 0;
80 if (ioctl(tty_fd, TCSETAW, &tty_set ) == -1 )
82 printf(
"ERROR: ioctl() failed to set settings!\n");
107 struct termio tty_set;
109 if (ioctl(tty_fd, TCGETA, &tty_set ) == -1 )
111 printf(
"ERROR: ioctl() failed to read settings!\n");
116 tty_set.c_cflag &= ~CBAUD;
117 tty_set.c_cflag |= speed;
119 if (ioctl(tty_fd, TCSETAW, &tty_set ) == -1 )
121 printf(
"ERROR: ioctl() failed to set settings!\n");
146 if (( bytes_out = write(tty_fd, p_buffer, nb_byte)) < nb_byte)
148 printf(
"ERROR: write() failed!\n");
182 while (tries < 2 && !ready)
188 FD_SET(tty_fd, &fds);
189 if (select(FD_SETSIZE, &fds, 0, 0, &tz) > 0)
191 qu_new = read(tty_fd, &p_buffer[bytes_read], (nb_bytes_max - bytes_read));
193 bytes_read += qu_new;
196 ready = (bytes_read == nb_bytes_max);
240 while (max_time_secs--)
246 FD_SET(tty_fd, &fds);
248 if (select(FD_SETSIZE, &fds, 0, 0, &tz) > 0)
273 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)