1

I'm trying to to program a serial communication using hardware handshake in linux using C/C++. The signals that implement the handshake are CTS (Clear to send) and RTS (Request to send). Currently my function for setting the CTS signal looks as follows:

int setCTS(int fd, int value) {
    int status;
    ioctl(fd, TIOCMGET, &status); // get the current port status
    if (value)
        status |= TIOCM_CTS; // rise the CTS bit
    else
        status &= ~TIOCM_CTS; // drop the CTS bit
    ioctl(fd, TIOCMSET, $status); // set the modified status
    return 0;
}

where fd is the file descriptor for the port and value is the value to be set for the signal. To code this function I based on http://www.easysw.com/~mike/serial/serial.html#5_1.

The problem is that gcc does not recognize any of the constants used in the example. Any suggestions?

-- Update --

I've found an answer. Looking to another example, sys/ioctl.h declares the constants.

1
  • I find grep useful for answering these kinds of questions - just search all the files in the include path. Aug 14, 2009 at 19:21

1 Answer 1

3

This may not be applicable for your particular application, but I thought I'd post it here in case it helps you or someone else searching.

On most systems with termios, you can set the CRTSCTS flag in the ->c_cflags member of the termios structure that you pass to tcsetattr, and have the kernel or hardware do the RTS/CTS flow control for you.

(It's not POSIX, but it's on both BSD and SystemV derived systems so it's almost everywhere - including Linux).

1
  • I second this. You really really want to let the line-discipline handle the throttling of CTS/RTS up and down for your application.
    – codeDr
    Aug 26, 2009 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.