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

int SerialStreamBuf::InitializeSerialPort (  )  [private]

This routine is called by open() in order to initialize some parameters of the serial port and setting its parameters to default values.

Returns:
-1 on failure and some other value on success.

Definition at line 101 of file SerialStreamBuf.cc.

References mFileDescriptor, and SetParametersToDefault().

                                      {
    //
    // If we do not have a valid file descriptor then return with
    // failure.
    //
    if( -1 == this->mFileDescriptor ) {
        return -1 ;
    }
    //
    // Use non-blocking mode while configuring the serial port. 
    //
    int flags = fcntl(this->mFileDescriptor, F_GETFL, 0) ;
    if( -1 == fcntl( this->mFileDescriptor, 
                     F_SETFL, 
                     flags | O_NONBLOCK ) ) {
        return -1 ;
    }
    //
    // Flush out any garbage left behind in the buffers associated
    // with the port from any previous operations. 
    //
    if( -1 == tcflush(this->mFileDescriptor, TCIOFLUSH) ) {
        return -1 ;
    }
    //
    // Set up the default configuration for the serial port. 
    //
    if( -1 == this->SetParametersToDefault() ) {
        return -1 ;
    }
    //
    // Allow all further communications to happen in blocking 
    // mode. 
    //
    flags = fcntl(this->mFileDescriptor, F_GETFL, 0) ;
    if( -1 == fcntl( this->mFileDescriptor, 
                     F_SETFL, 
                     flags & ~O_NONBLOCK ) ) {
        return -1 ;
    }
    //
    // If we get here without problems then we are good; return a value
    // different from -1.
    //
    return 0 ;
}


Generated by  Doxygen 1.6.0   Back to index