From 5d21340928cd46b3cb97cae0b9c707a71ef9ced0 Mon Sep 17 00:00:00 2001 From: Tero Kontkanen Date: Wed, 16 Aug 2017 16:14:16 -0700 Subject: Sets serial port in low latency mode in Linux --- pcserialport.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pcserialport.c b/pcserialport.c index 5134a6d..8cbe281 100644 --- a/pcserialport.c +++ b/pcserialport.c @@ -25,6 +25,11 @@ #include #include +#if defined(__linux__) +//needed for setting low latency +#include +#endif + #if defined(__APPLE__) #include #include @@ -178,6 +183,20 @@ smint32 serialPortOpen(const char * port_device_name, smint32 baudrate_bps) return -1; } #endif + + #if defined(TIOCGSERIAL) && defined(ASYNC_LOW_LATENCY) + struct serial_struct serial; + if(ioctl(port_handle, TIOCGSERIAL, &serial)!=-1) + { + serial.flags |= ASYNC_LOW_LATENCY; + if(ioctl(port_handle, TIOCSSERIAL, &serial) == -1 ) + { + smDebug(-1, Low, "Serial port warning: unable to set low latency mode, maybe try running with root permissions."); + } + } + else + smDebug(-1, Low, "Serial port warning: unable to read TIOCGSERIAL for low latency mode, maybe try running with root permissions."); + #endif //flush any stray bytes from device receive buffer that may reside in it //note: according to following page, delay before this may be necessary http://stackoverflow.com/questions/13013387/clearing-the-serial-ports-buffer -- cgit v1.2.3