#include #include #include #include #include #include #include void tty_raw(int fd) { struct termios raw; if (tcgetattr(fd, &raw) == -1) { fprintf(stderr, "tcgetattr\r\n"); exit(1); } raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); raw.c_oflag &= ~(OPOST); raw.c_cflag |= (CS8); raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); raw.c_cc[VMIN] = 0; raw.c_cc[VTIME] = 0; /* immediate - anything */ if (tcsetattr(fd, TCSAFLUSH, &raw) < 0) { fprintf(stderr, "can't set raw mode\r\n"); exit(1); } } int main(int argc, char** argv) { int fd = open("/dev/ttyUSB0", O_RDWR); struct termios tty; memset(&tty, 0, sizeof tty); tcgetattr(fd, &tty); cfsetospeed(&tty, B460800); cfsetispeed(&tty, B460800); tcsetattr(fd, TCSANOW, &tty); tty_raw(fd); int i = 0; for (;;) { char d[100]; int len = sprintf(d, "data %d", i++); write(fd, d, len + 1); usleep(300000); } }