diff --git a/doc/modbus_rtu_set_serial_mode.txt b/doc/modbus_rtu_set_serial_mode.txt index 0876d95..3728c37 100644 --- a/doc/modbus_rtu_set_serial_mode.txt +++ b/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. diff --git a/src/modbus-rtu.c b/src/modbus-rtu.c index facca84..fc7696c 100644 --- a/src/modbus-rtu.c +++ b/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) { diff --git a/src/modbus-rtu.h b/src/modbus-rtu.h index 4cbb375..51e15f1 100644 --- a/src/modbus-rtu.h +++ b/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_ */