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

short SerialStreamBuf::SetNumOfStopBits ( short  stop_bits  ) 

Set the number of stop bits used during serial communication. The only valid values are 1 and 2.

Parameters:
stop_bits The number of stop bits. (1 or 2).
Returns:
The number of stop bits or -1 on failure.

Definition at line 445 of file SerialStreamBuf.cc.

References mFileDescriptor, and NumOfStopBits().

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

                                                 {
    if( -1 == mFileDescriptor ) {
        return 0 ;
    }
    //
    // Get the current terminal settings. 
    //
    struct termios term_setting ;
    if( -1 == tcgetattr(mFileDescriptor, &term_setting) ) {
        return 0 ;
    }
    switch( stop_bits ) {
    case 1:
        term_setting.c_cflag &= ~CSTOPB ;
        break ;
    case 2:
        term_setting.c_cflag |= CSTOPB ;
        break ;
    default: 
        return 0 ;
        break ;
    }
    //
    // Set the new settings for the serial port. 
    //
    if( -1 == tcsetattr(mFileDescriptor, TCSANOW, &term_setting) ) {
        return 0 ;
    } 
    return this->NumOfStopBits() ;
}


Generated by  Doxygen 1.6.0   Back to index