5#include <libserial/SerialStream.h>
11constexpr const char*
const SERIAL_PORT_2 =
"/dev/ttyUSB1" ;
20int main(
int argc,
char** argv)
22 using namespace LibSerial ;
27 std::cerr <<
"Usage: " << argv[0] <<
" <filename>" << std::endl ;
34 std::ifstream input_file(argv[1]) ;
37 if (!input_file.good())
39 std::cerr <<
"Error: Could not open file "
40 << argv[1] <<
" for reading." << std::endl ;
50 serial_stream.
Open(SERIAL_PORT_2) ;
54 std::cerr <<
"The serial port did not open correctly." << std::endl ;
68 serial_stream.
SetParity(Parity::PARITY_NONE) ;
74 std::cout <<
"Writing input file contents to the serial port." << std::endl ;
82 input_file.read(&data_byte, 1) ;
85 serial_stream.write(&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.
SerialStream is a stream class for accessing serial ports on POSIX operating systems....
void DrainWriteBuffer()
Waits until the write buffer is drained and then returns.
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.
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, bool exclusive=true)
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.