43       usleep(milliseconds*1000); 
 
   51         vector<serial::PortInfo>::iterator iter = devices_found.begin();
 
   53         while( iter != devices_found.end() )
 
   57                 printf( 
"(%s, %s, %s)\n", device.
port.c_str(), device.
description.c_str(),
 
   64         cerr << 
"Usage: test_serial {-e|<serial port address>} ";
 
   65     cerr << 
"<baudrate> [test string]" << endl;
 
   68 int run(
int argc, 
char **argv)
 
   88   unsigned long baud = 0;
 
   89 #if defined(WIN32) && !defined(__MINGW32__) 
   90   sscanf_s(argv[2], 
"%lu", &baud);
 
   92   sscanf(argv[2], 
"%lu", &baud);
 
   98   cout << 
"Is the serial port open?";
 
  100     cout << 
" Yes." << endl;
 
  102     cout << 
" No." << endl;
 
  108     test_string = argv[3];
 
  110     test_string = 
"Testing.";
 
  114   cout << 
"Timeout == 1000ms, asking for 1 more byte than written." << endl;
 
  116     size_t bytes_wrote = my_serial.
write(test_string);
 
  118     string result = my_serial.
read(test_string.length()+1);
 
  120     cout << 
"Iteration: " << count << 
", Bytes written: ";
 
  121     cout << bytes_wrote << 
", Bytes read: ";
 
  122     cout << result.length() << 
", String read: " << result << endl;
 
  130   cout << 
"Timeout == 250ms, asking for 1 more byte than written." << endl;
 
  132     size_t bytes_wrote = my_serial.
write(test_string);
 
  134     string result = my_serial.
read(test_string.length()+1);
 
  136     cout << 
"Iteration: " << count << 
", Bytes written: ";
 
  137     cout << bytes_wrote << 
", Bytes read: ";
 
  138     cout << result.length() << 
", String read: " << result << endl;
 
  145   cout << 
"Timeout == 250ms, asking for exactly what was written." << endl;
 
  147     size_t bytes_wrote = my_serial.
write(test_string);
 
  149     string result = my_serial.
read(test_string.length());
 
  151     cout << 
"Iteration: " << count << 
", Bytes written: ";
 
  152     cout << bytes_wrote << 
", Bytes read: ";
 
  153     cout << result.length() << 
", String read: " << result << endl;
 
  160   cout << 
"Timeout == 250ms, asking for 1 less than was written." << endl;
 
  162     size_t bytes_wrote = my_serial.
write(test_string);
 
  164     string result = my_serial.
read(test_string.length()-1);
 
  166     cout << 
"Iteration: " << count << 
", Bytes written: ";
 
  167     cout << bytes_wrote << 
", Bytes read: ";
 
  168     cout << result.length() << 
", String read: " << result << endl;
 
  176 int main(
int argc, 
char **argv) {
 
  178     return run(argc, argv);
 
  179   } 
catch (exception &e) {
 
  180     cerr << 
"Unhandled Exception: " << e.what() << endl;