Skip to content

Commit a290304

Browse files
authored
Merge pull request #209 from arnefmeyer/development
update serial to properly open devices on Linux
2 parents 0408beb + 37b40c5 commit a290304

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Source/Processors/Serial/ofSerial.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <dirent.h>
1313
#endif
1414

15+
#ifdef TARGET_LINUX
16+
#include <linux/serial.h>
17+
#endif
1518

1619
#pragma comment(lib, "setupapi.lib")
1720
#include <fcntl.h>
@@ -418,8 +421,21 @@ bool ofSerial::setup(string portName, int baud)
418421
options.c_cflag &= ~PARENB;
419422
options.c_cflag &= ~CSTOPB;
420423
options.c_cflag &= ~CSIZE;
424+
options.c_iflag &= (tcflag_t) ~(INLCR | IGNCR | ICRNL | IGNBRK);
425+
options.c_oflag &= (tcflag_t) ~(OPOST);
426+
#if defined( TARGET_LINUX )
427+
options.c_cflag |= CRTSCTS;
428+
options.c_lflag &= ~(ICANON | ECHO | ISIG);
429+
#endif
421430
options.c_cflag |= CS8;
422431
tcsetattr(fd,TCSANOW,&options);
432+
#ifdef TARGET_LINUX
433+
struct serial_struct kernel_serial_settings;
434+
if (ioctl(fd, TIOCGSERIAL, &kernel_serial_settings) == 0) {
435+
kernel_serial_settings.flags |= ASYNC_LOW_LATENCY;
436+
ioctl(fd, TIOCSSERIAL, &kernel_serial_settings);
437+
}
438+
#endif
423439

424440
bInited = true;
425441
printf("Success in opening serial connection!\n\n");

0 commit comments

Comments
 (0)