#include #include #include #include // from http://www.control.com/thread/1026231695 // // To compile: // gcc -o manual-set-rs232-signals.o manual-set-rs232-signals.c main() { int fd, sercmd, serstat; fd = open("/dev/ttyUSB9", O_RDONLY); // Open the serial port. //TIOCM_LE DSR (data set ready/line enable) //TIOCM_DTR DTR (data terminal ready) //TIOCM_RTS RTS (request to send) //TIOCM_ST Secondary TXD (transmit) //TIOCM_SR Secondary RXD (receive) //TIOCM_CTS CTS (clear to send) //TIOCM_CAR DCD (data carrier detect) //TIOCM_CD see TIOCM_CAR //TIOCM_RNG RNG (ring) //TIOCM_RI see TIOCM_RNG //TIOCM_DSR DSR (data set ready) sercmd = TIOCM_RTS; printf("Setting the RTS pin.\n"); ioctl(fd, TIOCMBIS, &sercmd); // Set the RTS pin. // Read the RTS pin status. ioctl(fd, TIOCMGET, &serstat); if (serstat & TIOCM_RTS) printf("RTS pin is set.\n"); else printf("RTS pin is reset.\n"); getchar(); // Wait for the return key before continuing. printf("Resetting the RTS pin.\n"); ioctl(fd, TIOCMBIC, &sercmd); // Reset the RTS pin. // Read the RTS pin status. ioctl(fd, TIOCMGET, &serstat); if (serstat & TIOCM_RTS) printf("RTS pin is set.\n"); else printf("RTS pin is reset.\n"); close(fd); }