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

const SerialStreamBuf::BaudRateEnum SerialStreamBuf::SetBaudRate ( const BaudRateEnum  baud_rate  ) 

If is_open() != true, return -1. Otherwise, set the baud rate of the associated serial port. Return the baud rate on success and BAUD_INVALID on failure.

Definition at line 226 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, BaudRate(), and mFileDescriptor.

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

                                                         {
    if( -1 == mFileDescriptor ) {
        return BAUD_INVALID ;
    }
    switch (baud_rate) {
    case BAUD_50:
    case BAUD_75:   
    case BAUD_110:  
    case BAUD_134:  
    case BAUD_150:  
    case BAUD_200:  
    case BAUD_300:  
    case BAUD_600:  
    case BAUD_1200: 
    case BAUD_1800: 
    case BAUD_2400: 
    case BAUD_4800: 
    case BAUD_9600: 
    case BAUD_19200:
    case BAUD_38400:
    case BAUD_57600:
    case BAUD_115200:
        //
        // Get the current terminal settings. 
        //
        struct termios term_setting ;
        if( -1 == tcgetattr(mFileDescriptor, &term_setting) ) {
            return BAUD_INVALID ;
        }
        //
        // Modify the baud rate in the term_setting structure.
        //
        cfsetispeed( &term_setting, baud_rate ) ;
        cfsetospeed( &term_setting, baud_rate ) ;
        //
        // Apply the modified termios structure to the serial 
        // port. 
        //
        if( -1 == tcsetattr(mFileDescriptor, TCSANOW, &term_setting) ) {
            return BAUD_INVALID ;
        }
        break ;
    default:
        //
        // :TODO: Thu Jul 13 16:30:14 2000 Pagey
        //
        // There is obviously a problem if we reach here. The method
        // must have been called with an invalid value of the baud
        // rate. We should probably throw an exception here. I will
        // print something on cerr for the time being but leave the
        // stream in "good" state. 
        //
        return BAUD_INVALID ;
        break ;
    } ;
    //
    // If we succeeded in setting the baud rate then we need to return
    // the baud rate. 
    //
    return BaudRate() ;
}


Generated by  Doxygen 1.6.0   Back to index