2

I'm developing a serial communication application on Ubuntu. I'm using a pl2303 converter and libserial.

Myy issue is that I'm unable to set the baud rate. After executing the source code below I'm getting error state=2.

My source code is:

bool setUpCom()
{
    SerialStream my_serial_stream ;
    my_serial_stream.Open( "/dev/ttyUSB0" ) ;

    if ( ! my_serial_stream.good() )
    {
        printf("\nNo COM Port");
        return false;
    }

    my_serial_stream.SetBaudRate( SerialStreamBuf::BAUD_115200 );   
    my_serial_stream.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;

   if ( ! my_serial_stream.good() )
   {  
       std::cerr << "Error setting serial port state=2" ;
       return false; 
   }

   my_serial_stream.SetNumOfStopBits(1) ;

   if ( ! my_serial_stream.good() )
   {
       std::cerr << "Error setting serial port state=3" ;
       return false;
   }

   my_serial_stream.SetParity( SerialStreamBuf::PARITY_NONE ) ;

   if ( ! my_serial_stream.good() )
   {
       std::cerr << "Error setting serial port state=4" ;
       return false;
   }

   my_serial_stream.SetBaudRate( SerialStreamBuf::BAUD_115200 );

   if ( ! my_serial_stream.good() )
   {
       std::cerr << "Error setting serial port state =5" ;
       return false;
   }
}
Mike
  • 47,263
  • 29
  • 113
  • 177
Nimo shr
  • 23
  • 4

1 Answers1

0

Are you sure that invoking my_serial_stream.good() is good?

In http://libserial.sourceforge.net/doxygen/class_lib_serial_1_1_serial_stream.html it is not listed. There is a IsOpen() method instead.

Ottavio Campana
  • 4,088
  • 5
  • 31
  • 58
  • The latest examples seem to refer to it (http://libserial.svn.sourceforge.net/viewvc/libserial/trunk/examples/read_port.cpp?revision=110&view=markup), looks like they're behind on their docs. – dsolimano Oct 04 '12 at 12:26