diff options
| author | Tero Kontkanen <tero.k@granitedevices.com> | 2017-08-16 16:14:16 -0700 |
|---|---|---|
| committer | Tero Kontkanen <tero.k@granitedevices.com> | 2017-08-16 16:14:16 -0700 |
| commit | 5d21340928cd46b3cb97cae0b9c707a71ef9ced0 (patch) | |
| tree | a6cc56b740fbd8b0282672ae34c855013be4554a | |
| parent | 1f684939334775303db6bd150e04b0249a79de63 (diff) | |
| download | SimpleMotionV2-5d21340928cd46b3cb97cae0b9c707a71ef9ced0.tar.gz SimpleMotionV2-5d21340928cd46b3cb97cae0b9c707a71ef9ced0.zip | |
Sets serial port in low latency mode in Linux
| -rw-r--r-- | pcserialport.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/pcserialport.c b/pcserialport.c index 5134a6d..8cbe281 100644 --- a/pcserialport.c +++ b/pcserialport.c @@ -25,6 +25,11 @@ #include <sys/types.h> #include <string.h> +#if defined(__linux__) +//needed for setting low latency +#include <linux/serial.h> +#endif + #if defined(__APPLE__) #include <CoreFoundation/CoreFoundation.h> #include <IOKit/IOKitLib.h> @@ -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 |
