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

const SerialStreamBuf::ParityEnum SerialStreamBuf::SetParity ( const ParityEnum  parity  ) 

Set the parity for serial communication.

Parameters:
parity The parity value.

Definition at line 500 of file SerialStreamBuf.cc.

References mFileDescriptor, Parity(), PARITY_EVEN, PARITY_INVALID, PARITY_NONE, and PARITY_ODD.

Referenced by SetParametersToDefault(), and LibSerial::SerialStream::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 ;
    }
    //
    // Set the parity in the termios structure. 
    //
    switch( parity ) {
    case PARITY_EVEN:
        term_setting.c_cflag |= PARENB ;
        term_setting.c_cflag &= ~PARODD ;
        break ;
    case PARITY_ODD:
        term_setting.c_cflag |= PARENB ;
        term_setting.c_cflag |= PARODD ;
        break ;
    case PARITY_NONE:
        term_setting.c_cflag &= ~PARENB ;
        break ;
    default:
        return PARITY_INVALID ;
    }
    //
    // Write the settings back to the serial port. 
    //
    if( -1 == tcsetattr(mFileDescriptor, TCSANOW, &term_setting) ) {
        return PARITY_INVALID ;
    } 
    return Parity() ;
}


Generated by  Doxygen 1.6.0   Back to index