5#include <libserial/SerialStream.h>
11constexpr const char*
const SERIAL_PORT_1 =
"/dev/ttyUSB0" ;
19 using namespace LibSerial ;
27 serial_stream.
Open(SERIAL_PORT_1) ;
31 std::cerr <<
"The serial port did not open correctly." << std::endl ;
45 serial_stream.
SetParity(Parity::PARITY_NONE) ;
51 while(serial_stream.rdbuf()->in_avail() == 0)
63 serial_stream.get(data_byte) ;
66 std::cout << data_byte ;
73 std::cout <<
"Done." << std::endl ;
Exception error thrown when the serial port could not be opened.
SerialStream is a stream class for accessing serial ports on POSIX operating systems....
void SetCharacterSize(const CharacterSize &characterSize)
Sets the character size for the serial port.
void SetBaudRate(const BaudRate &baudRate)
Sets the baud rate for the serial port to the specified value.
bool IsDataAvailable()
Checks if data is available at the input of the serial port.
void SetFlowControl(const FlowControl &flowControlType)
Sets flow control for the serial port.
void SetStopBits(const StopBits &stopBits)
Sets the number of stop bits to be used with the serial port.
void Open(const std::string &fileName, const std::ios_base::openmode &openMode=std::ios_base::in|std::ios_base::out)
Opens the serial port associated with the specified file name and the specified mode.
void SetParity(const Parity &parityType)
Sets the parity type for the serial port.