stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.29k stars 1.71k forks source link

Building on Cygwin #24

Closed xatom closed 12 years ago

xatom commented 12 years ago

I've successfully built libmodbus master on Cygwin with a few minor modifications. The stumbling block was the configuration flags HAVE_DECL_TIOCSRS485: since there's no Linux kernel present, this flag is guaranteed to be 0 on Cygwin, but it cut out otherwise valid code for both ioctl and part of the modbus_rtu_t structure.

I've included a patch with the changes I made. As a side-note, I modified .gitignore to so *.exe files are ignored as well; this allows building of the test suite without git asking questions.

Included is a patch detailing the changes from master I've made to fix the problem. This may not be the correct way to go about these changes—C is not my language of choice, so I may be unaware of particular conventions or subtle language pitfalls.

diff --git a/.gitignore b/.gitignore
index ddd7705..a41c5a4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,14 +30,14 @@ modbus-version.h
 stamp-h1
 *.o
 *~
-tests/bandwidth-client
-tests/bandwidth-server-many-up
-tests/bandwidth-server-one
-tests/random-test-client
-tests/random-test-server
-tests/unit-test-client
-tests/unit-test-server
-tests/version
+tests/bandwidth-client*
+tests/bandwidth-server-many-up*
+tests/bandwidth-server-one*
+tests/random-test-client*
+tests/random-test-server*
+tests/unit-test-client*
+tests/unit-test-server*
+tests/version*
 doc/*.html
 doc/*.3
 doc/*.7
diff --git a/src/modbus-rtu-private.h b/src/modbus-rtu-private.h
index d0bc615..3e19dc8 100644
--- a/src/modbus-rtu-private.h
+++ b/src/modbus-rtu-private.h
@@ -84,8 +84,8 @@ typedef struct _modbus_rtu {
 #endif
 #if HAVE_DECL_TIOCSRS485
     int serial_mode;
-    int rts;
 #endif
+    int rts;
 } modbus_rtu_t;

 #endif /* _MODBUS_RTU_PRIVATE_H_ */
diff --git a/src/modbus-rtu.c b/src/modbus-rtu.c
index d694bb6..7e1a71b 100644
--- a/src/modbus-rtu.c
+++ b/src/modbus-rtu.c
@@ -31,8 +31,11 @@
 #include "modbus-rtu.h"
 #include "modbus-rtu-private.h"

-#if HAVE_DECL_TIOCSRS485
+#if HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
+
+#if HAVE_LINUX_SERIAL_H
 #include <linux/serial.h>
 #endif
xatom commented 12 years ago

Perhaps this patch should be ignored. I was looking through closed bug reports, and it was mentioned that libmodbus has not been designed to work with Cygwin. Having built the library, but running into several bugs when trying to use it, it's become apparent that making this library work with Cygwin is not a light undertaking, and one that I am personally unable to tackle at this time.

Having said that, trying to run a full GNU system on top of Windows is a bit like putting an Formula 1 suspension in a Plymouth Reliant — sure, now it handles like it's on rails, but that doesn't change the fact that the car itself is an unreliable dog.

I'll attempt building with MinGW, see if I can solve my dilemma in that direction. I have no access to a real operating system, so I'll have to make due.