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

const SerialStreamBuf::ParityEnum SerialStreamBuf::Parity (  )  const

Get the current parity setting for the serial port.

Returns:
The parity setting for the serial port.

Definition at line 539 of file SerialStreamBuf.cc.

References mFileDescriptor, PARITY_EVEN, PARITY_INVALID, PARITY_NONE, and PARITY_ODD.

Referenced by LibSerial::SerialStream::Parity(), and SetParity().

                              {
    if( -1 == mFileDescriptor ) {
        return PARITY_INVALID ;
    }
    //
    // Get the current terminal settings. 
    //
    struct termios term_setting ;
    if( -1 == tcgetattr(mFileDescriptor, &term_setting) ) {
        return PARITY_INVALID ;
    }
    //
    // Get the parity setting from the termios structure. 
    //
    if( term_setting.c_cflag & PARENB ) {   // parity is enabled.
        if( term_setting.c_cflag & PARODD ) { // odd parity
            return PARITY_ODD ; 
        } else {                              // even parity
            return PARITY_EVEN ;
        }
    } else {                                // no parity.
        return PARITY_NONE ;
    }
    return PARITY_INVALID ; // execution should never reach here. 
}


Generated by  Doxygen 1.6.0   Back to index