5#include <libserial/SerialPort.h>
11constexpr const char*
const SERIAL_PORT_2 =
"/dev/ttyUSB1" ;
19int main(
int argc,
char** argv)
21 using namespace LibSerial ;
26 std::cerr <<
"Usage: " << argv[0] <<
" <filename>" << std::endl ;
33 std::ifstream input_file(argv[1]) ;
36 if (!input_file.good())
38 std::cerr <<
"Error: Could not open file "
39 << argv[1] <<
" for reading." << std::endl ;
49 serial_port.
Open(SERIAL_PORT_2) ;
53 std::cerr <<
"The serial port did not open correctly." << std::endl ;
67 serial_port.
SetParity(Parity::PARITY_NONE) ;
73 std::cout <<
"Writing input file contents to the serial port." << std::endl ;
82 input_file.read(&data_byte, 1) ;
91 std::cout << data_byte ;
95 std::cout <<
"The example program successfully completed!" << std::endl ;
Exception error thrown when the serial port could not be opened.
SerialPort allows an object oriented approach to serial port communication. A serial port object can ...
void SetBaudRate(const BaudRate &baudRate)
Sets the baud rate for the serial port to the specified value.
void SetParity(const Parity &parityType)
Sets the parity type for 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 WriteByte(char charbuffer)
Writes a single byte to the serial port.
void SetFlowControl(const FlowControl &flowControlType)
Sets flow control for the serial port.
void SetCharacterSize(const CharacterSize &characterSize)
Sets the character size for the serial port.
void DrainWriteBuffer()
Waits until the write buffer is drained and then returns.
void SetStopBits(const StopBits &stopBits)
Sets the number of stop bits to be used with the serial port.