Permalink
Browse files

Merge pull request #68 from sebseb7/osx_baud

mac osx >= 10.4 can handle higher baud rates
  • Loading branch information...
2 parents 5bd84ff + 3b868e9 commit e229cae674cd7ee6b8ffe66f3b2a9cf72c58b4f3 @voodootikigod voodootikigod committed Aug 24, 2012
Showing with 24 additions and 1 deletion.
  1. +24 −1 src/serialport_unix.cpp
View
@@ -6,6 +6,16 @@
#include <errno.h>
#include <termios.h>
+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#endif
+#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
+#include <sys/ioctl.h>
+#include <IOKit/serial/ioss.h>
+#include <errno.h>
+#endif
+
+
int ToBaudConstant(int baudRate);
int ToDataBitsConstant(int dataBits);
int ToStopBitsConstant(SerialPortStopBits stopBits);
@@ -71,12 +81,13 @@ int ToFlowControlConstant(bool flowControl) {
void EIO_Open(uv_work_t* req) {
OpenBaton* data = static_cast<OpenBaton*>(req->data);
+#if not ( defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4) )
int baudRate = ToBaudConstant(data->baudRate);
if(baudRate == -1) {
sprintf(data->errorString, "Invalid baud rate setting %d", data->baudRate);
return;
}
-
+#endif
int dataBits = ToDataBitsConstant(data->dataBits);
if(dataBits == -1) {
sprintf(data->errorString, "Invalid data bits setting %d", data->dataBits);
@@ -111,9 +122,11 @@ void EIO_Open(uv_work_t* req) {
// Set baud and other configuration.
tcgetattr(fd, &options);
+#if not ( defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4) )
// Specify the baud rate
cfsetispeed(&options, baudRate);
cfsetospeed(&options, baudRate);
+#endif
// Specify data bits
options.c_cflag &= ~CSIZE;
@@ -176,6 +189,16 @@ void EIO_Open(uv_work_t* req) {
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &options);
+
+#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
+ speed_t speed = data->baudRate;
+ if ( ioctl( fd, IOSSIOSPEED, &speed ) == -1 )
+ {
+ printf( "Error %d calling ioctl( ..., IOSSIOSPEED, ... )\n", errno );
+ }
+#endif
+
+
data->result = fd;
}

0 comments on commit e229cae

Please sign in to comment.