/* * This program cycles DTR. * Do not use stdin because we must open with O_NONBLOCK. */ #include #include #include #include #include #include /* Provides TIOCMBIC/TIOCMBIS */ #include #include /* This comes from , which cannot be included */ #define TIOCM_DTR 0x002 #define TIOCM_RTS 0x004 #define NAME "cycle" void Usage(void); int main(int argc, char *argv[]) { char *name; int fd; unsigned int b; if (argc != 2) Usage(); name = argv[1]; /* * Standard nonblocking open for Linux. */ if ((fd = open(name, O_RDWR|O_NONBLOCK)) < 0) { fprintf(stderr, NAME ": Cannot open %s: %s\n", name, strerror(errno)); exit(1); } /* (void) ioctl(fd, TCFLSH, TCIOFLUSH); */ /* make the serial port blocking again */ (void) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK); /* * Cycle DTR */ printf("Dropping DTR...\n"); b = TIOCM_DTR; if (ioctl(fd, TIOCMBIC, &b) != 0) { fprintf(stderr, NAME ": TIOCMBIC %s: %s\n", name, strerror(errno)); exit(1); } printf("Sleeping...\n"); sleep(5); printf("Raising DTR...\n"); b = TIOCM_DTR; if (ioctl(fd, TIOCMBIS, &b) != 0) { fprintf(stderr, NAME ": TIOCMBIS %s: %s\n", name, strerror(errno)); exit(1); } printf("Sleeping...\n"); sleep(5); exit(0); } void Usage() { fprintf(stderr, "Usage: cycle device\n"); exit(1); }