From 3b868e9248839bf310a05c56c43073eb738b68dd Mon Sep 17 00:00:00 2001 From: Seb Date: Mon, 30 Jul 2012 05:51:54 +0200 Subject: [PATCH] mac osx >= 10.4 can handle higher baud rates --- src/serialport_unix.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/serialport_unix.cpp b/src/serialport_unix.cpp index 5d1445b..a3b010c 100644 --- a/src/serialport_unix.cpp +++ b/src/serialport_unix.cpp @@ -6,6 +6,16 @@ #include #include +#ifdef __APPLE__ +#include +#endif +#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4) +#include +#include +#include +#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(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; }