Skip to content

Commit 5e12241

Browse files
committed
Co-authored-by: Mqx <Mqxx@users.noreply.github.com>
1 parent e12c6f3 commit 5e12241

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/src/serial_unix.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <algorithm>
12
#if defined(__unix__) || defined(__unix) || defined(__APPLE__)
23
#include "serial.h"
34
#include <fstream>
@@ -140,6 +141,25 @@ auto serialRead(
140141
const int timeout,
141142
const int multiplier
142143
) -> int {
144+
145+
if (ioctl(hSerialPort, TCGETS2, &tty) == -1){
146+
errorCallback(status(StatusCodes::SET_STATE_ERROR));
147+
return 0;
148+
}
149+
150+
if (timeout > 0 && timeout < 100) {
151+
tty.c_cc[VTIME] = 1;
152+
} else {
153+
tty.c_cc[VTIME] = timeout / 100;
154+
}
155+
156+
tty.c_cc[VMIN] = bufferSize;
157+
158+
if (ioctl(hSerialPort, TCSETS2, &tty) == -1){
159+
errorCallback(status(StatusCodes::SET_STATE_ERROR));
160+
return 0;
161+
}
162+
143163
int bytesRead = read(hSerialPort, static_cast<char*>(buffer), bufferSize);
144164

145165
if (bytesRead >= 0){

0 commit comments

Comments
 (0)