Skip to content

Commit

Permalink
fixed issue with latency on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
masf7g committed May 6, 2020
1 parent 07d6e14 commit 89289b2
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/SCSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "SCSerial.h"

#if !defined(ARDUINO) && !defined(_MSC_VER)
#include <fcntl.h>
#include <sys/select.h>
#include <fcntl.h>
#include <sys/select.h>
#endif

SCSerial::SCSerial(SerialIO* pSerial)
Expand Down Expand Up @@ -215,7 +215,10 @@ void WindowsSerial::flush() {
PurgeComm(serial_handle_, PURGE_RXABORT | PURGE_RXCLEAR);
}

#else
#elif defined(__linux__)
#include <sys/ioctl.h>
#include <linux/serial.h>

// LinuxSerial

bool LinuxSerial::begin(int baudRate, const char* serialPort)
Expand Down Expand Up @@ -291,12 +294,18 @@ bool LinuxSerial::setBaudRate(int baudRate)
curopt.c_cflag |= CLOCAL;//disable modem status check
cfmakeraw(&curopt);//make raw mode
curopt.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
if(tcsetattr(fd, TCSANOW, &curopt) == 0){
return true;
}else{
perror("tcsetattr:");
if(tcsetattr(fd, TCSANOW, &curopt) != 0)
return false;
}

struct serial_struct serinfo;
serinfo.reserved_char[0] = 0;
if( ioctl(fd, TIOCGSERIAL, &serinfo) < 0 )
return false;
serinfo.flags |= ASYNC_LOW_LATENCY;
if( ioctl(fd, TIOCSSERIAL, &serinfo) < 0 )
return false;

return true;
}

void LinuxSerial::end()
Expand Down

0 comments on commit 89289b2

Please sign in to comment.