Forráskód Böngészése

Export the MODBUS_RTU_RS232/485 and rtu_set_serial_mode on all platforms

Stéphane Raimbault 13 éve
szülő
commit
e97b72e3dc
3 módosított fájl, 12 hozzáadás és 6 törlés
  1. 4 1
      doc/modbus_rtu_set_serial_mode.txt
  2. 8 2
      src/modbus-rtu.c
  3. 0 3
      src/modbus-rtu.h

+ 4 - 1
doc/modbus_rtu_set_serial_mode.txt

@@ -30,7 +30,7 @@ mode:
  automation because it can be used effectively over long distances and in
  electrically noisy environments.
 
-This function is only available on Linux kernels 2.6.28 onwards.
+This function is only supported on Linux kernels 2.6.28 onwards.
 
 
 RETURN VALUE
@@ -44,6 +44,9 @@ ERRORS
 *EINVAL*::
 The current libmodbus backend is not RTU.
 
+*ENOTSUP*::
+The function is not supported on your platform.
+
 If the call to ioctl() fails, the error code of ioctl will be returned.
 
 

+ 8 - 2
src/modbus-rtu.c

@@ -704,10 +704,10 @@ static int _modbus_rtu_connect(modbus_t *ctx)
     return 0;
 }
 
-#if defined(HAVE_DECL_TIOCSRS485)
 int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode)
 {
     if (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU) {
+#if defined(HAVE_DECL_TIOCSRS485)
         modbus_rtu_t *ctx_rtu = ctx->backend_data;
         struct serial_rs485 rs485conf;
         memset(&rs485conf, 0x0, sizeof(struct serial_rs485));
@@ -728,6 +728,13 @@ int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode)
             ctx_rtu->serial_mode = MODBUS_RTU_RS232;
             return 0;
         }
+#else
+        if (ctx->debug) {
+            fprintf(stderr, "This function isn't supported on your platform\n");
+        }
+        errno = ENOTSUP;
+        return -1;
+#endif
     }
 
     /* Wrong backend and invalid mode specified */
@@ -744,7 +751,6 @@ int modbus_rtu_get_serial_mode(modbus_t *ctx) {
         return -1;
     }
 }
-#endif
 
 void _modbus_rtu_close(modbus_t *ctx)
 {

+ 0 - 3
src/modbus-rtu.h

@@ -28,13 +28,10 @@
 modbus_t* modbus_new_rtu(const char *device, int baud, char parity,
                          int data_bit, int stop_bit);
 
-#if defined(linux)
-/* On Linux, we can tell the kernel for RS485 communication */
 #define MODBUS_RTU_RS232 0
 #define MODBUS_RTU_RS485 1
 
 int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode);
 int modbus_rtu_get_serial_mode(modbus_t *ctx);
-#endif
 
 #endif /* _MODBUS_RTU_H_ */