From e7212210dcb3aba5e2edd1b62dc8789ff7eb6016 Mon Sep 17 00:00:00 2001 From: Seb Date: Tue, 3 Apr 2012 04:56:17 +0200 Subject: [PATCH] 500000 baud support for osx (termios.h does not support 500000 on osx --- serialport_native/serialport_native.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/serialport_native/serialport_native.cc b/serialport_native/serialport_native.cc index 3d1f5a6..fb70135 100644 --- a/serialport_native/serialport_native.cc +++ b/serialport_native/serialport_native.cc @@ -12,6 +12,15 @@ #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 + #define THROW_BAD_ARGS ThrowException(Exception::TypeError(String::New("Bad argument"))) @@ -96,12 +105,20 @@ namespace node { // Set baud and other configuration. tcgetattr(fd, &options); + printf("Setting baud rate to %ld\n", Baud_Rate); +#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4) + speed_t speed = Baud_Rate; + if ( ioctl( fd, IOSSIOSPEED, &speed ) == -1 ) + { + printf( "Error %d calling ioctl( ..., IOSSIOSPEED, ... )\n", errno ); + } +#else BAUD = GetBaudConstant(Baud_Rate); - printf("Setting baud rate to %ld\n", BAUD); /* Specify the baud rate */ cfsetispeed(&options, BAUD); cfsetospeed(&options, BAUD); +#endif tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &options);