Merge pull request #42 from sebseb7/master

500000 baud support on MaxOSX
This commit is contained in:
Chris Williams 2012-05-14 06:33:31 -07:00
commit aabbd418c7
2 changed files with 23 additions and 3 deletions

View file

@ -11,7 +11,7 @@ var net = require('net');
var serialport_native = require('bindings')('serialport_native.node');
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];

View file

@ -12,6 +12,15 @@
#include <node_buffer.h>
#include <v8.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
#define THROW_BAD_ARGS ThrowException(Exception::TypeError(String::New("Bad argument")))
@ -19,11 +28,14 @@
namespace node {
using namespace v8;
static Persistent<String> errno_symbol;
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;
@ -93,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);