Go to the documentation of this file.
21 std::unique_ptr<CSerialPort> serPort;
25 cout <<
"Serial port test application: Use it with a loopback serial "
26 "port (pins 2-3 connected)"
29 cout <<
"Enter the serial port name (e.g. COM1, ttyS0, ttyUSB0): ";
30 getline(cin, serName);
33 cout <<
"Opening serial port...";
34 serPort = std::make_unique<CSerialPort>(serName);
37 cout <<
"Setting timeouts...";
41 cout <<
"Setting baud rate...";
45 for (
int i = 0; i < 10; i++)
48 cout <<
"Writing test data...";
49 const char buf1[] =
"Hello world!";
50 size_t written = serPort->
Write(buf1,
sizeof(buf1));
51 cout << written <<
" bytes written." << endl;
54 cout <<
"Reading data...";
56 size_t nRead = serPort->
Read(buf2,
sizeof(buf2));
57 cout << nRead <<
" bytes read: '";
60 cout << buf2 <<
"'" << endl;
63 catch (
const std::exception& e)
65 cerr << e.what() << endl;
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.
size_t Read(void *Buffer, size_t Count) override
Implements the virtual method responsible for reading from the stream - Unlike CStream::ReadBuffer,...
Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 15:49:54 UTC 2020 | |