Reputation: 23
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;
}
}
Upvotes: 2
Views: 606
Reputation: 4188
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.
Upvotes: 0