From 6ff2eef121011c823b9a601016b679aa81dd63b0 Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Wed, 26 Mar 2008 10:38:01 +0100 Subject: [PATCH] Support of MacOSX, based on the work of Matthew Butch. Need testing. --- modbus/modbus.c | 17 +++++++++++++---- modbus/modbus.h | 14 +++++++++++++- wscript | 16 ++++++++++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/modbus/modbus.c b/modbus/modbus.c index 2daa000..eb30004 100644 --- a/modbus/modbus.c +++ b/modbus/modbus.c @@ -29,7 +29,6 @@ http://www.easysw.com/~mike/serial/serial.html */ -#include #include #include #include @@ -37,6 +36,8 @@ #include #include #include +#include +#include /* TCP */ #include @@ -45,9 +46,15 @@ #include #include #include +#include #include "modbus.h" +#ifdef SYS_PLATFORM_DARWIN + #include + #define SOL_CTP getprotobyname("TCP")->p_proto +#endif + #define UNKNOWN_ERROR_MSG "Not defined in modbus specification" static const int SIZE_TAB_ERROR_MSG = 12; @@ -1292,9 +1299,11 @@ static int modbus_connect_rtu(modbus_param_t *mb_param) tios.c_cflag |= PARODD; } - /* Read your man page for the meaning of all this (man - termios). Its a bit to involved to comment here :) */ - tios.c_line = 0; + /* Read the man page of termios if you need more information. */ + + /* This field isn't used on POSIX systems + tios.c_line = 0; + */ /* C_LFLAG Line options diff --git a/modbus/modbus.h b/modbus/modbus.h index 59ae7bc..84637c7 100644 --- a/modbus/modbus.h +++ b/modbus/modbus.h @@ -109,11 +109,23 @@ typedef enum { RTU, TCP } type_com_t; +/* This structure is byte-aligned */ typedef struct { /* Communication : RTU or TCP */ type_com_t type_com; - /* Device: "/dev/ttyS0" or "/dev/ttyUSB0" */ + + /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" + on Mac OS X for KeySpan USB<->Serial adapters this string + had to be made bigger on OS X as the directory+file name + was bigger than 19 bytes. Making it 67 bytes for now, but + OS X does support 256 byte file names. May become a problem + in the future. */ +#ifdef SYS_PLATFORM_DARWIN + char device[67]; +#else char device[19]; +#endif + /* Parity: "even", "odd", "none" */ char parity[5]; /* Bauds: 19200 */ diff --git a/wscript b/wscript index b5faa4c..25b7e0d 100644 --- a/wscript +++ b/wscript @@ -16,9 +16,10 @@ def configure(conf): conf.check_tool('compiler_cc') conf.check_tool('misc') - headers = 'arpa/inet.h fcntl.h netinet/in.h stdlib.h \ - string.h sys/ioctl.h sys/socket.h sys/time.h \ - termios.h unistd.h' + headers = 'stdio.h string.h stdlib.h termios.h sys/time.h \ + unistd.h errno.h limits.h fcntl.h \ + sys/types.h sys/socket.h sys/ioctl.h \ + netinet/in.h netinet/ip.h netinet/tcp.h arpa/inet.h' # check for headers and append found headers to headers_found for later use headers_found = [] @@ -27,6 +28,7 @@ def configure(conf): headers_found.append(header) functions_defines = ( + ('setsockopt', 'HAVE_SETSOCKOPT'), ('inet_ntoa', 'HAVE_INET_NTOA'), ('memset', 'HAVE_MEMSET'), ('select', 'HAVE_SELECT'), @@ -39,10 +41,16 @@ def configure(conf): e.headers = headers_found e.define = define e.run() - + conf.define('VERSION', VERSION) conf.define('PACKAGE', 'libmodbus') + import sys + if sys.platform[:6] == 'darwin': + print "Darwin platform detected" + conf.env.append_value('CCFLAGS', '-DPLATFORM_DARWIN') + conf.define('PLATFORM_DARWIN', '1') + conf.write_config_header() def build(bld): -- libgit2 0.21.4