23 #include "../../include/ecl/devices/serial.hpp" 36 std::cout <<
"Usage: demo_serial_timeouts [port]" << std::endl;
37 std::cout << std::endl;
38 std::cout <<
" default value for port is /dev/ttyUSB0" << std::endl;
45 int main(
int argc,
char **argv) {
47 std::string port(
"/dev/ttyUSB0");
49 std::string arg(argv[1]);
50 if ( arg ==
"--help" ) {
57 std::cout << std::endl;
58 std::cout <<
"***********************************************************" << std::endl;
59 std::cout <<
" Serial Timeouts" << std::endl;
60 std::cout <<
"***********************************************************" << std::endl;
61 std::cout <<
"* For demo'ing low latency read timeouts on posix systems." << std::endl;
62 std::cout <<
"* Timeouts < 100ms use a custom loop, > 100ms use termios." << std::endl;
63 std::cout <<
"* Hook this up to a serial cable to test (actual" << std::endl;
64 std::cout <<
"* connection not important)." << std::endl;
65 std::cout <<
"***********************************************************" << std::endl;
66 std::cout << std::endl;
72 std::cout <<
"[ERROR] : error opening " << port << std::endl;
73 std::cout << std::endl;
77 TimeStamp time, pre_read_time;
80 std::cout << std::endl;
81 std::cout <<
"***********************************************************" << std::endl;
82 std::cout <<
" 100 ms timeouts" << std::endl;
83 std::cout <<
"***********************************************************" << std::endl;
84 std::cout <<
"* This will use termios to scan." << std::endl;
85 std::cout <<
"***********************************************************" << std::endl;
86 std::cout << std::endl;
89 for (
unsigned int i = 0; i < 10; ++i ) {
90 pre_read_time.stamp();
91 long result = serial.read(buffer,256);
94 std::cout <<
"[INFO] : read " << result <<
" bytes." << std::endl;
95 }
else if ( result == 0 ) {
96 std::cout <<
"[INFO] : timed out [" << (time - pre_read_time) <<
"]." << std::endl;
98 std::cout <<
"[INFO] : error " << result <<
"." << std::endl;
102 std::cout << std::endl;
103 std::cout <<
"***********************************************************" << std::endl;
104 std::cout <<
" 50 ms timeouts" << std::endl;
105 std::cout <<
"***********************************************************" << std::endl;
106 std::cout <<
"* This will internally scan with 5ms loops." << std::endl;
107 std::cout <<
"***********************************************************" << std::endl;
108 std::cout << std::endl;
115 for (
unsigned int i = 0; i < 10; ++i ) {
116 pre_read_time.stamp();
117 long result = serial.read(buffer,256);
120 std::cout <<
"[INFO] : read " << result <<
" bytes." << std::endl;
121 }
else if ( result == 0 ) {
122 std::cout <<
"[INFO] : timed out [" << (time - pre_read_time) <<
"]." << std::endl;
124 std::cout <<
"[INFO] : error " << result <<
"." << std::endl;
127 std::cout << std::endl;
128 std::cout <<
"***********************************************************" << std::endl;
129 std::cout <<
" 20 ms timeouts" << std::endl;
130 std::cout <<
"***********************************************************" << std::endl;
131 std::cout <<
"* This will internally scan with 2ms loops." << std::endl;
132 std::cout <<
"***********************************************************" << std::endl;
133 std::cout << std::endl;
136 for (
unsigned int i = 0; i < 10; ++i ) {
137 pre_read_time.stamp();
138 long result = serial.read(buffer,256);
141 std::cout <<
"[INFO] : read " << result <<
" bytes." << std::endl;
142 }
else if ( result == 0 ) {
143 std::cout <<
"[INFO] : timed out [" << (time - pre_read_time) <<
"]." << std::endl;
145 std::cout <<
"[INFO] : error " << result <<
"." << std::endl;
148 std::cout << std::endl;
149 std::cout <<
"***********************************************************" << std::endl;
150 std::cout <<
" 5 ms timeouts" << std::endl;
151 std::cout <<
"***********************************************************" << std::endl;
152 std::cout <<
"* This will internally scan with 1ms loops." << std::endl;
153 std::cout <<
"***********************************************************" << std::endl;
154 std::cout << std::endl;
157 for (
unsigned int i = 0; i < 10; ++i ) {
158 pre_read_time.stamp();
159 long result = serial.read(buffer,256);
162 std::cout <<
"[INFO] : read " << result <<
" bytes." << std::endl;
163 }
else if ( result == 0 ) {
164 std::cout <<
"[INFO] : timed out [" << (time - pre_read_time) <<
"]." << std::endl;
166 std::cout <<
"[INFO] : error " << result <<
"." << std::endl;
Embedded control libraries.
int main(int argc, char **argv)