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

const SerialStreamBuf::BaudRateEnum SerialStream::BaudRate (  ) 

Get the current baud rate being used for serial communication. This routine queries the serial port for its current settings and returns the baud rate that is being used by the serial port.

Returns:
The current baud rate for the serial port. Note: this is not a constant function because it checks to see that it is dealing with a SerialStream with a non-null buffer. If the buffer is null, it attempts to set the state of the stream accordingly.

Definition at line 71 of file SerialStream.cc.

References LibSerial::SerialStreamBuf::BAUD_INVALID, and LibSerial::SerialStreamBuf::BaudRate().

                       {
    SerialStreamBuf* my_buffer = dynamic_cast<SerialStreamBuf *>(this->rdbuf()) ;
    //
    // Make sure that we are dealing with a SerialStreamBuf before
    // proceeding. This check also makes sure that we have a non-NULL
    // buffer associated with this stream.
    //
    if( my_buffer ) {
        //
        // Try to set the baud rate. If the corresponding function of the
        // SerialStreamBuf class returns BAUD_INVALID, then we have a
        // problem and the stream is no longer valid for I/O.
        //
        return my_buffer->BaudRate() ;
    } else {
        //
        // If the dynamic_cast above failed then we either have a NULL
        // streambuf associated with this stream or we have a buffer of
        // class other than SerialStreamBuf. In either case, we have a
        // problem and we should stop all I/O using this stream.
        //
        setstate(badbit) ;
        return SerialStreamBuf::BAUD_INVALID ;
    }
}


Generated by  Doxygen 1.6.0   Back to index