1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 11:44:53 +08:00
serial/tests/serial_tests.cc

36 lines
760 B
C++
Raw Normal View History

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