2012-01-12 12:46:08 -06:00
|
|
|
#include <string>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include "serial/serial.h"
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::cout;
|
|
|
|
|
using std::endl;
|
|
|
|
|
using serial::Serial;
|
2012-01-15 02:06:38 -06:00
|
|
|
using serial::SerialExecption;
|
2012-01-12 12:46:08 -06:00
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2012-01-15 02:06:38 -06:00
|
|
|
try {
|
2012-01-17 12:35:32 -06:00
|
|
|
Serial s("/dev/tty.usbserial-A900adHq", 115200, 100);
|
2012-01-15 02:06:38 -06:00
|
|
|
s.flush();
|
|
|
|
|
long long count = 0;
|
|
|
|
|
while (1) {
|
|
|
|
|
// size_t available = s.available();
|
|
|
|
|
// cout << "avialable: " << available << endl;
|
2012-01-17 15:52:57 -06:00
|
|
|
string line = s.readline();
|
2012-01-17 12:35:32 -06:00
|
|
|
if (line.empty())
|
|
|
|
|
cout << "Nothing\n";
|
2012-01-15 02:06:38 -06:00
|
|
|
cout << count << ": " << line << line.length() << endl;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (SerialExecption e)
|
|
|
|
|
{
|
|
|
|
|
cout << "Caught SerialException: " << e.what() << endl;
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
cout << "Caught an error." << endl;
|
2012-01-12 12:46:08 -06:00
|
|
|
}
|
|
|
|
|
}
|