소스 검색

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

Stéphane Raimbault 17 년 전
부모
커밋
6ff2eef121
3개의 변경된 파일38개의 추가작업 그리고 9개의 파일을 삭제
  1. 13 4
      modbus/modbus.c
  2. 13 1
      modbus/modbus.h
  3. 12 4
      wscript

+ 13 - 4
modbus/modbus.c

@@ -29,7 +29,6 @@
    http://www.easysw.com/~mike/serial/serial.html
 */
 
-#include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -37,6 +36,8 @@
 #include <sys/time.h>
 #include <unistd.h>
 #include <errno.h>
+#include <limits.h>
+#include <fcntl.h>
 
 /* TCP */
 #include <sys/types.h>
@@ -45,9 +46,15 @@
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
+#include <arpa/inet.h>
 
 #include "modbus.h"
 
+#ifdef SYS_PLATFORM_DARWIN
+    #include <netdb.h>
+    #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 
 

+ 13 - 1
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 */

+ 12 - 4
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):