Commit 6ff2eef121011c823b9a601016b679aa81dd63b0

Authored by Stéphane Raimbault
1 parent 2f75f7a1

Support of MacOSX, based on the work of Matthew Butch.

Need testing.
modbus/modbus.c
@@ -29,7 +29,6 @@ @@ -29,7 +29,6 @@
29 http://www.easysw.com/~mike/serial/serial.html 29 http://www.easysw.com/~mike/serial/serial.html
30 */ 30 */
31 31
32 -#include <fcntl.h>  
33 #include <stdio.h> 32 #include <stdio.h>
34 #include <string.h> 33 #include <string.h>
35 #include <stdlib.h> 34 #include <stdlib.h>
@@ -37,6 +36,8 @@ @@ -37,6 +36,8 @@
37 #include <sys/time.h> 36 #include <sys/time.h>
38 #include <unistd.h> 37 #include <unistd.h>
39 #include <errno.h> 38 #include <errno.h>
  39 +#include <limits.h>
  40 +#include <fcntl.h>
40 41
41 /* TCP */ 42 /* TCP */
42 #include <sys/types.h> 43 #include <sys/types.h>
@@ -45,9 +46,15 @@ @@ -45,9 +46,15 @@
45 #include <netinet/in.h> 46 #include <netinet/in.h>
46 #include <netinet/ip.h> 47 #include <netinet/ip.h>
47 #include <netinet/tcp.h> 48 #include <netinet/tcp.h>
  49 +#include <arpa/inet.h>
48 50
49 #include "modbus.h" 51 #include "modbus.h"
50 52
  53 +#ifdef SYS_PLATFORM_DARWIN
  54 + #include <netdb.h>
  55 + #define SOL_CTP getprotobyname("TCP")->p_proto
  56 +#endif
  57 +
51 #define UNKNOWN_ERROR_MSG "Not defined in modbus specification" 58 #define UNKNOWN_ERROR_MSG "Not defined in modbus specification"
52 59
53 static const int SIZE_TAB_ERROR_MSG = 12; 60 static const int SIZE_TAB_ERROR_MSG = 12;
@@ -1292,9 +1299,11 @@ static int modbus_connect_rtu(modbus_param_t *mb_param) @@ -1292,9 +1299,11 @@ static int modbus_connect_rtu(modbus_param_t *mb_param)
1292 tios.c_cflag |= PARODD; 1299 tios.c_cflag |= PARODD;
1293 } 1300 }
1294 1301
1295 - /* Read your man page for the meaning of all this (man  
1296 - termios). Its a bit to involved to comment here :) */  
1297 - tios.c_line = 0; 1302 + /* Read the man page of termios if you need more information. */
  1303 +
  1304 + /* This field isn't used on POSIX systems
  1305 + tios.c_line = 0;
  1306 + */
1298 1307
1299 /* C_LFLAG Line options 1308 /* C_LFLAG Line options
1300 1309
modbus/modbus.h
@@ -109,11 +109,23 @@ @@ -109,11 +109,23 @@
109 109
110 typedef enum { RTU, TCP } type_com_t; 110 typedef enum { RTU, TCP } type_com_t;
111 111
  112 +/* This structure is byte-aligned */
112 typedef struct { 113 typedef struct {
113 /* Communication : RTU or TCP */ 114 /* Communication : RTU or TCP */
114 type_com_t type_com; 115 type_com_t type_com;
115 - /* Device: "/dev/ttyS0" or "/dev/ttyUSB0" */ 116 +
  117 + /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*"
  118 + on Mac OS X for KeySpan USB<->Serial adapters this string
  119 + had to be made bigger on OS X as the directory+file name
  120 + was bigger than 19 bytes. Making it 67 bytes for now, but
  121 + OS X does support 256 byte file names. May become a problem
  122 + in the future. */
  123 +#ifdef SYS_PLATFORM_DARWIN
  124 + char device[67];
  125 +#else
116 char device[19]; 126 char device[19];
  127 +#endif
  128 +
117 /* Parity: "even", "odd", "none" */ 129 /* Parity: "even", "odd", "none" */
118 char parity[5]; 130 char parity[5];
119 /* Bauds: 19200 */ 131 /* Bauds: 19200 */
@@ -16,9 +16,10 @@ def configure(conf): @@ -16,9 +16,10 @@ def configure(conf):
16 conf.check_tool('compiler_cc') 16 conf.check_tool('compiler_cc')
17 conf.check_tool('misc') 17 conf.check_tool('misc')
18 18
19 - headers = 'arpa/inet.h fcntl.h netinet/in.h stdlib.h \  
20 - string.h sys/ioctl.h sys/socket.h sys/time.h \  
21 - termios.h unistd.h' 19 + headers = 'stdio.h string.h stdlib.h termios.h sys/time.h \
  20 + unistd.h errno.h limits.h fcntl.h \
  21 + sys/types.h sys/socket.h sys/ioctl.h \
  22 + netinet/in.h netinet/ip.h netinet/tcp.h arpa/inet.h'
22 23
23 # check for headers and append found headers to headers_found for later use 24 # check for headers and append found headers to headers_found for later use
24 headers_found = [] 25 headers_found = []
@@ -27,6 +28,7 @@ def configure(conf): @@ -27,6 +28,7 @@ def configure(conf):
27 headers_found.append(header) 28 headers_found.append(header)
28 29
29 functions_defines = ( 30 functions_defines = (
  31 + ('setsockopt', 'HAVE_SETSOCKOPT'),
30 ('inet_ntoa', 'HAVE_INET_NTOA'), 32 ('inet_ntoa', 'HAVE_INET_NTOA'),
31 ('memset', 'HAVE_MEMSET'), 33 ('memset', 'HAVE_MEMSET'),
32 ('select', 'HAVE_SELECT'), 34 ('select', 'HAVE_SELECT'),
@@ -39,10 +41,16 @@ def configure(conf): @@ -39,10 +41,16 @@ def configure(conf):
39 e.headers = headers_found 41 e.headers = headers_found
40 e.define = define 42 e.define = define
41 e.run() 43 e.run()
42 - 44 +
43 conf.define('VERSION', VERSION) 45 conf.define('VERSION', VERSION)
44 conf.define('PACKAGE', 'libmodbus') 46 conf.define('PACKAGE', 'libmodbus')
45 47
  48 + import sys
  49 + if sys.platform[:6] == 'darwin':
  50 + print "Darwin platform detected"
  51 + conf.env.append_value('CCFLAGS', '-DPLATFORM_DARWIN')
  52 + conf.define('PLATFORM_DARWIN', '1')
  53 +
46 conf.write_config_header() 54 conf.write_config_header()
47 55
48 def build(bld): 56 def build(bld):