Logo Search packages:      
Sourcecode: libserial version File versions  Download package

const SerialStreamBuf::FlowControlEnum SerialStreamBuf::SetFlowControl ( const FlowControlEnum  flow_c  ) 

Use the specified flow control.

Definition at line 566 of file SerialStreamBuf.cc.

References CTRL_Q, CTRL_S, FLOW_CONTROL_HARD, FLOW_CONTROL_INVALID, FLOW_CONTROL_SOFT, FlowControl(), and mFileDescriptor.

Referenced by LibSerial::SerialStream::SetFlowControl(), and SetParametersToDefault().

                                                            {
    if( -1 == mFileDescriptor ) {
        return FLOW_CONTROL_INVALID ;
    }
    //
    // Flush any unwritten, unread data from the serial port. 
    //
    if( -1 == tcflush(mFileDescriptor, TCIOFLUSH) ) {
        return FLOW_CONTROL_INVALID ;
    }
    //
    // Get the current terminal settings. 
    //
    struct termios tset;
    int retval = tcgetattr(mFileDescriptor, &tset);
    if (-1 == retval) {
        return FLOW_CONTROL_INVALID ;
    }
    //
    // Set the flow control. Hardware flow control uses the RTS (Ready
    // To Send) and CTS (clear to Send) lines. Software flow control
    // uses IXON|IXOFF
    //
    if ( FLOW_CONTROL_HARD == flow_c ) {
        tset.c_iflag &= ~ (IXON|IXOFF);
        tset.c_cflag |= CRTSCTS;
        tset.c_cc[VSTART] = _POSIX_VDISABLE;
        tset.c_cc[VSTOP] = _POSIX_VDISABLE;
    } else if ( FLOW_CONTROL_SOFT == flow_c ) {
        tset.c_iflag |= IXON|IXOFF;
        tset.c_cflag &= ~CRTSCTS;
        tset.c_cc[VSTART] = CTRL_Q ; // 0x11 (021) ^q
        tset.c_cc[VSTOP]  = CTRL_S ; // 0x13 (023) ^s
    } else {
        tset.c_iflag &= ~(IXON|IXOFF);        
        tset.c_cflag &= ~CRTSCTS;
    }
    retval = tcsetattr(mFileDescriptor, TCSANOW, &tset);
    if (-1 == retval) {
        return FLOW_CONTROL_INVALID ;
    }
    return FlowControl() ;
}


Generated by  Doxygen 1.6.0   Back to index