8N1 9600
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <termios.h> #include <string.h> int main(int argc, char **argv) { struct termios tio; int tty_fd; fd_set rdset; unsigned char c = 0; memset(&tio, 0, sizeof(tio)); tio.c_iflag = 0; tio.c_oflag = 0; tio.c_cflag = CS8 | CREAD | CLOCAL; tio.c_lflag = 0; tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 5; tio.c_iflag &= ~(ISTRIP | ICRNL ); tio.c_oflag &= ~OPOST; tio.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO); tty_fd = open("/dev/ttyU0", O_RDWR | O_NONBLOCK); cfsetospeed(&tio, B9600); cfsetispeed(&tio, B9600); tcsetattr(tty_fd, TCSANOW, &tio); while (1) { if (read(tty_fd, &c, 1) > 0) printf("%c", c); } close(tty_fd); } /* EOF */