// testserial.c #include #include #include #include #include int main(int argc, char *argv[]) { // const int rts_bit = TIOCM_RTS; // const int dtr_bit = TIOCM_DTR; int i, fd, flags; if (argc != 2) { fprintf(stderr, "Usage: testserial /dev/cua0\n"); return 1; } if ((fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) { perror("testserial"); return 1; } // Now DTR and RTS should be high // ioctl(fd, TIOCMBIS, &rts_bit); // set RTS (high) // ioctl(fd, TIOCMBIC, &rts_bit); // clear RTS (low) // ioctl(fd, TIOCMBIS, &dtr_bit); // set DTR (high) // ioctl(fd, TIOCMBIC, &dtr_bit); // clear DTR (low) for (i = 0; i < 100; i++) { ioctl(fd, TIOCMGET, &flags); printf("DSR = %4s, CTS = %4s\n", (flags & TIOCM_DSR) ? "high" : "low", (flags & TIOCM_CTS) ? "high" : "low"); sleep(1); // in seconds // usleep(100000); // in microseconds } close(fd); // close, or just terminate this process // Now DTR and RTS should be low return 0; }