mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
Fixing timeouts, there were not functioning correctly.
This commit is contained in:
parent
04f81f23ed
commit
fe61b346da
@ -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<int> (timeout_ % 1000);
|
||||
timeout.tv_usec = static_cast<int> (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<size_t> (bytes_read);
|
||||
}
|
||||
@ -298,8 +302,6 @@ void
|
||||
Serial::SerialImpl::setTimeout (long timeout)
|
||||
{
|
||||
timeout_ = timeout;
|
||||
if (isOpen_)
|
||||
reconfigurePort ();
|
||||
}
|
||||
|
||||
long
|
||||
|
||||
@ -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++;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user