Browse Source

Fix compile failure in modbus_rtu_get_serial_mode() without RS485 support

When there's no RS485 support available (e.g. on Win32), the modbus_rtu_t
data structure does not have the serial_mode member. It therefore must
not be used in modbus_rtu_get_serial_mode() if HAVE_DECL_TIOCSRS485 is
not defined. Fixes Win32 build with recent versions of libmodbus.
Tobias Doerffel 13 years ago
parent
commit
4583f5ceee
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/modbus-rtu.c

+ 8 - 0
src/modbus-rtu.c

@@ -745,8 +745,16 @@ int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode)
 
 int modbus_rtu_get_serial_mode(modbus_t *ctx) {
     if (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU) {
+#if defined(HAVE_DECL_TIOCSRS485)
         modbus_rtu_t *ctx_rtu = ctx->backend_data;
         return ctx_rtu->serial_mode;
+#else
+        if (ctx->debug) {
+            fprintf(stderr, "This function isn't supported on your platform\n");
+        }
+        errno = ENOTSUP;
+        return -1;
+#endif
     } else {
         errno = EINVAL;
         return -1;