Hello
I'm coding a program that needs to monitor changes in serial port control signals (cts, rts, dtr, dcd), to be more specific I'm interested in cts changes.
Is there any blocking system call that can be called, and only return when a specified control line is set or unset.
The only other way I can think of doing it is an infinite loop
I know this is not a good way of doing it, and hope there is some sort of blocking system call that would just return when the control signal I'm interested in changes value.Code:int cts_set = 0; int status; ioctl(fd, TIOCMGET, &status); if (status & TIOCM_CTS) cts_set = 1; while (do_work) { ioctl(fd, TIOCMGET, &status); if ((status & TIOCM_CTS) && (!cts_set)) { // CTS was unset, now set cts_set = 1; // Do work } else if ((!(status & TIOCM_CTS)) && (cts_set)) { // CTS was set, now unset cts_set = 0; // Do work } usleep(200000); }
Thanks in advance



LinkBack URL
About LinkBacks



