#include /* Standard input/output definitions */ #include /* String function definitions */ #include /* UNIX standard function definitions */ #include /* File control definitions */ #include /* Error number definitions */ #include /* POSIX terminal control definitions */ int main(int argc, char **argv){ int fd; struct termios options; char buffer[128]; /* Input buffer */ int nbytes; /* Number of bytes read */ int tries; /* Number of tries so far */ fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY); fcntl(fd, F_SETFL, 0); if (fd == -1)perror("open_port: Unable to open /dev/ttyUSB0 - "); fcntl(fd, F_SETFL, 0); /* get the current options */ tcgetattr(fd, &options); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_iflag &= ~(IXON | IXOFF | IXANY); options.c_oflag &= ~OPOST; /* * Set the baud rates to 19200... */ cfsetispeed(&options, B19200); cfsetospeed(&options, B19200); /* set the options */ tcsetattr(fd, TCSANOW, &options); for(;;){ nbytes = read(fd,&buffer,sizeof(buffer)); printf("nbytes = %i; buffer = %32.32x\n",nbytes,buffer); } close(fd); return 0; }