#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 */ /* * * 'open_port()' - Open serial port 1. * * * * Returns the file descriptor on success or -1 on error. * */ int open_port(void) { int fd; /* File descriptor for the port */ fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { /* * * Could not open the port. * */ perror("open_port: Unable to open /dev/ttyUSB0 - "); } else fcntl(fd, F_SETFL, 0); return (fd); } /*n = write(fd, "ATZ\r", 4); if (n < 0) fputs("write() of 4 bytes failed!\n", stderr); */ fcntl(fd, F_SETFL, FNDELAY); /* put our read code here */ fcntl(fd, F_SETFL, FNDELAY); close(fd);