mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
Merge pull request #68 from sebseb7/osx_baud
mac osx >= 10.4 can handle higher baud rates
This commit is contained in:
commit
e229cae674
1 changed files with 24 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue