From eb669444305eb86dc355ef67ff5b7c1895a591b1 Mon Sep 17 00:00:00 2001 From: dodo Date: Mon, 30 Jan 2012 23:58:09 +0100 Subject: [PATCH 1/3] add 500000 BAUD rate --- serialport.js | 2 +- serialport_native/serialport_native.cc | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/serialport.js b/serialport.js index 1101d0a..10c5c89 100644 --- a/serialport.js +++ b/serialport.js @@ -11,7 +11,7 @@ var net = require('net'); var serialport_native = require('./serialport_native'); var IOWatcher = process.binding('io_watcher').IOWatcher; -var BAUDRATES = [115200, 57600, 38400, 19200, 9600, 4800, 2400, 1800, 1200, 600, 300, 200, 150, 134, 110, 75, 50]; +var BAUDRATES = [500000, 230400, 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1800, 1200, 600, 300, 200, 150, 134, 110, 75, 50]; var DATABITS = [8, 7, 6, 5]; var STOPBITS = [1, 2]; var PARITY = [0, 1, 2]; diff --git a/serialport_native/serialport_native.cc b/serialport_native/serialport_native.cc index 0156a54..e52381e 100644 --- a/serialport_native/serialport_native.cc +++ b/serialport_native/serialport_native.cc @@ -19,11 +19,12 @@ namespace node { using namespace v8; - + static Persistent errno_symbol; static long GetBaudConstant(long Baud_Rate) { switch (Baud_Rate) { + case 500000: return B500000; case 230400: return B230400; case 115200: return B115200; case 57600: return B57600; From 1868ae2f16d3f19e5a6e0907b97d1c625b7c855b Mon Sep 17 00:00:00 2001 From: Seb Date: Tue, 3 Apr 2012 04:32:36 +0200 Subject: [PATCH 2/3] B500000 is not available on any system --- serialport_native/serialport_native.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serialport_native/serialport_native.cc b/serialport_native/serialport_native.cc index e52381e..3d1f5a6 100644 --- a/serialport_native/serialport_native.cc +++ b/serialport_native/serialport_native.cc @@ -24,7 +24,9 @@ namespace node { static long GetBaudConstant(long Baud_Rate) { switch (Baud_Rate) { +#ifdef B500000 case 500000: return B500000; +#endif case 230400: return B230400; case 115200: return B115200; case 57600: return B57600; From e7212210dcb3aba5e2edd1b62dc8789ff7eb6016 Mon Sep 17 00:00:00 2001 From: Seb Date: Tue, 3 Apr 2012 04:56:17 +0200 Subject: [PATCH 3/3] 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);