Merge pull request #1 from justinh24/master

Fix custom baud rate for termios on apple
This commit is contained in:
James Bowman 2019-02-25 15:24:08 -08:00 committed by GitHub
commit 2851205ffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -126,14 +126,15 @@ int openSerialPort(const char *portname)
perror(portname); perror(portname);
return -1; return -1;
} }
tcgetattr(fd, &Settings); tcgetattr(fd, &Settings);
#if defined(__APPLE__) && !defined(B1000000)
#define B1000000 1000000
#endif
#if defined(__APPLE__) && !defined(B1000000)
#include <IOKit/serial/ioss.h>
#else
cfsetispeed(&Settings, B1000000); cfsetispeed(&Settings, B1000000);
cfsetospeed(&Settings, B1000000); cfsetospeed(&Settings, B1000000);
#endif
cfmakeraw(&Settings); cfmakeraw(&Settings);
Settings.c_cc[VMIN] = 1; Settings.c_cc[VMIN] = 1;
@ -142,6 +143,11 @@ int openSerialPort(const char *portname)
return -1; return -1;
} }
#if defined(__APPLE__) && !defined(B1000000)
speed_t speed = (speed_t)1000000;
ioctl(fd, IOSSIOSPEED, &speed);
#endif
return fd; return fd;
} }