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

int SerialStreamBuf::SetParametersToDefault (  ) 

Initialize the serial communication parameters to their default values.

Definition at line 149 of file SerialStreamBuf.cc.

References BAUD_INVALID, DEFAULT_BAUD, DEFAULT_CHAR_SIZE, DEFAULT_FLOW_CONTROL, DEFAULT_NO_OF_STOP_BITS, DEFAULT_PARITY, DEFAULT_VMIN, DEFAULT_VTIME, mFileDescriptor, SetBaudRate(), SetCharSize(), SetFlowControl(), SetNumOfStopBits(), SetParity(), SetVMin(), and SetVTime().

Referenced by InitializeSerialPort().

                                        {

    if( -1 == mFileDescriptor ) {
        return -1 ;
    }
    //
    // Set all values (also the ones, which are not covered by the
    // parametrisation-functions of this library).
    //
    struct termios tio;
    tio.c_iflag = IGNBRK;
    tio.c_oflag = 0;
    tio.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
    tio.c_lflag = 0;
    //
    // :TRICKY:
    // termios.c_line is not a standard element of the termios structure (as 
    // per the Single Unix Specification 2. This is only present under Linux.
    //
    #ifdef __linux__
    tio.c_line = '\0';
    #endif
    bzero( &tio.c_cc, sizeof(tio.c_cc) );
    tio.c_cc[VTIME] = 0;
    tio.c_cc[VMIN]  = 1;
    if ( -1 == tcsetattr(mFileDescriptor,TCSANOW,&tio) ) {
      return -1 ;
    }
    //
    // Baud rate
    //
    if( BAUD_INVALID == SetBaudRate(DEFAULT_BAUD) ) {
        return -1 ;
    } ;
    //
    // Character size. 
    //
    if( -1 == SetCharSize(DEFAULT_CHAR_SIZE) ) {
        return -1 ;
    }
    //
    // Number of stop bits. 
    //
    if( -1 == SetNumOfStopBits(DEFAULT_NO_OF_STOP_BITS) ) {
        return -1 ;
    }
    //
    // Parity
    //
    if( -1 == SetParity(DEFAULT_PARITY) ) {
        return -1 ;
    }
    //
    // Flow control
    //
    if( -1 == SetFlowControl(DEFAULT_FLOW_CONTROL) ) {
        return -1 ;
    }
    //
    // VMin
    //
    if ( -1 == SetVMin(DEFAULT_VMIN) ) {
        return -1 ;
    }
    //
    // VTime
    //
    if ( -1 == SetVTime(DEFAULT_VTIME) ) {
        return -1 ;
    }
    //
    // All done. Return a value other than -1. 
    //
    return 0 ;
}


Generated by  Doxygen 1.6.0   Back to index