#include #include #include using namespace mt4cpp; //return true means read more, return false means not read more bool predicate(const std::vector& buffer) { return buffer.empty() || buffer.back() != '\n'; } int main() { try { SerialPort s("/dev/ttyUSB0", boost::chrono::milliseconds(50) ); //SerialPort s("COM34", boost::chrono::milliseconds(50) ); std::vector in = s.read_if(predicate); //read until predicate or timeout std::cout << "read " << in.size() << " bytes " << std::endl; } catch(std::exception& e) { std::cerr << e.what() << std::endl; } return 0; }