diff --git a/src/impl/unix.cc b/src/impl/unix.cc index 5a7c89f..ed05141 100644 --- a/src/impl/unix.cc +++ b/src/impl/unix.cc @@ -236,7 +236,7 @@ Serial::SerialImpl::read (char* buf, size_t size) FD_SET (fd_, &readfds); struct timeval timeout; timeout.tv_sec = timeout_ / 1000; - timeout.tv_usec = static_cast (timeout_ % 1000); + timeout.tv_usec = static_cast (timeout_ % 1000) * 1000; int r = select (fd_ + 1, &readfds, NULL, NULL, &timeout); if (r == -1 && errno == EINTR) @@ -265,6 +265,10 @@ Serial::SerialImpl::read (char* buf, size_t size) } break; } + else + { + break; + } } return static_cast (bytes_read); } @@ -298,8 +302,6 @@ void Serial::SerialImpl::setTimeout (long timeout) { timeout_ = timeout; - if (isOpen_) - reconfigurePort (); } long diff --git a/tests/serial_tests.cc b/tests/serial_tests.cc index 184d99d..d52e1e6 100644 --- a/tests/serial_tests.cc +++ b/tests/serial_tests.cc @@ -11,13 +11,15 @@ using serial::SerialExecption; int main(int argc, char **argv) { try { - Serial s("/dev/tty.usbserial-A900adHq", 115200, 2000); + 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(); + string line = s.read(); + if (line.empty()) + cout << "Nothing\n"; cout << count << ": " << line << line.length() << endl; count++; }