Go to the documentation of this file.
24 cout <<
"Serial port test application: Use it with a loopback serial "
25 "port (pins 2-3 connected)"
28 cout <<
"Enter the serial port name (e.g. COM1, ttyS0, ttyUSB0): " ;
29 getline(cin, serName);
32 cout <<
"Opening serial port..." ;
36 cout <<
"Setting timeouts..." ;
40 cout <<
"Setting baud rate..." ;
44 for (
int i = 0; i < 10; i++)
47 cout <<
"Writing test data..." ;
48 const char buf1[] =
"Hello world!" ;
49 size_t written = serPort->
Write (buf1,
sizeof (buf1));
50 cout << written <<
" bytes written." << endl;
53 cout <<
"Reading data..." ;
55 size_t nRead = serPort->
Read (buf2,
sizeof (buf2));
56 cout << nRead <<
" bytes read: '" ;
59 cout << buf2 <<
"'" << endl;
64 catch (std::exception& e)
66 cerr << e.what() << endl;
size_t Read(void *Buffer, size_t Count)
Implements the virtual method responsible for reading from the stream - Unlike CStream::ReadBuffer,...
A communications serial port built as an implementation of a utils::CStream.
Serial and networking devices and utilities.
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
void setConfig(int baudRate, int parity=0, int bits=8, int nStopBits=1, bool enableFlowControl=false)
Changes the configuration of the port.
void setTimeouts(int ReadIntervalTimeout, int ReadTotalTimeoutMultiplier, int ReadTotalTimeoutConstant, int WriteTotalTimeoutMultiplier, int WriteTotalTimeoutConstant)
Changes the timeouts of the port, in milliseconds.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST