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

const SerialStreamBuf::BaudRateEnum SerialStreamBuf::BaudRate (  )  const

Return the current baud rate of the serial port. If the baud rate is not set to a valid value then it returns BAUD_INVALID.

Definition at line 289 of file SerialStreamBuf.cc.

References BAUD_110, BAUD_115200, BAUD_1200, BAUD_134, BAUD_150, BAUD_1800, BAUD_19200, BAUD_200, BAUD_2400, BAUD_300, BAUD_38400, BAUD_4800, BAUD_50, BAUD_57600, BAUD_600, BAUD_75, BAUD_9600, BAUD_INVALID, and mFileDescriptor.

Referenced by LibSerial::SerialStream::BaudRate(), and SetBaudRate().

                                {
    if( -1 == mFileDescriptor ) {
        return BAUD_INVALID ;
    }
    //
    // Get the current terminal settings. 
    //
    struct termios term_setting ;
    if( -1 == tcgetattr(mFileDescriptor, &term_setting) ) {
        return BAUD_INVALID ;
    }
    //
    // Read the input and output baud rates. 
    //
    speed_t input_baud = cfgetispeed( &term_setting ) ;
    speed_t output_baud = cfgetospeed( &term_setting ) ;
    //
    // Make sure that the input and output baud rates are
    // equal. Otherwise, we do not know which one to return.
    //
    if( input_baud != output_baud ) {
        return BAUD_INVALID ; 
    }
    switch( input_baud ) {
    case B50: 
        return BAUD_50 ; break ;
    case B75:
        return BAUD_75 ; break ;
    case B110: 
        return BAUD_110 ; break ;
    case B134: 
        return BAUD_134 ; break ;
    case B150:
        return BAUD_150 ; break ;
    case B200: 
        return BAUD_200 ; break ;
    case B300:
        return BAUD_300 ; break ;
    case B600:
        return BAUD_600 ; break ;
    case B1200:
        return BAUD_1200 ; break ;
    case B1800:
        return BAUD_1800 ; break ;
    case B2400: 
        return BAUD_2400 ; break ;
    case B4800:
        return BAUD_4800 ; break ;
    case B9600:
        return BAUD_9600 ; break ;
    case B19200:
        return BAUD_19200 ; break ;
    case B38400:
        return BAUD_38400 ; break ;
    case B57600:
        return BAUD_57600 ; break ;
    case B115200:
        return BAUD_115200 ; break ;
    default:
        return BAUD_INVALID ; // we return an invalid value in this case. 
        break ;
    }
    //
    // The code should never reach here due to the fact that the default
    // section of the above switch statement returns. So we force an
    // abort here using an assertion which will always fail.
    //
    assert( false ) ;
    return BAUD_INVALID ;
}


Generated by  Doxygen 1.6.0   Back to index