Fix custom baud rate for termios on apple

This commit is contained in:
Justin Hirsch 2019-02-25 15:13:21 -08:00
parent 3f4d177c21
commit f665595f0f
1 changed files with 10 additions and 4 deletions

View File

@ -126,14 +126,15 @@ int openSerialPort(const char *portname)
perror(portname);
return -1;
}
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);
cfsetospeed(&Settings, B1000000);
#endif
cfmakeraw(&Settings);
Settings.c_cc[VMIN] = 1;
@ -142,6 +143,11 @@ int openSerialPort(const char *portname)
return -1;
}
#if defined(__APPLE__) && !defined(B1000000)
speed_t speed = (speed_t)1000000;
ioctl(fd, IOSSIOSPEED, &speed);
#endif
return fd;
}