Commit 4583f5ceeec595794221a4e6fc92aa5c7b54714b
Committed by
Stéphane Raimbault
1 parent
876a8d0d
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.
Showing
1 changed file
with
8 additions
and
0 deletions
src/modbus-rtu.c
| @@ -745,8 +745,16 @@ int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode) | @@ -745,8 +745,16 @@ int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode) | ||
| 745 | 745 | ||
| 746 | int modbus_rtu_get_serial_mode(modbus_t *ctx) { | 746 | int modbus_rtu_get_serial_mode(modbus_t *ctx) { |
| 747 | if (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU) { | 747 | if (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU) { |
| 748 | +#if defined(HAVE_DECL_TIOCSRS485) | ||
| 748 | modbus_rtu_t *ctx_rtu = ctx->backend_data; | 749 | modbus_rtu_t *ctx_rtu = ctx->backend_data; |
| 749 | return ctx_rtu->serial_mode; | 750 | return ctx_rtu->serial_mode; |
| 751 | +#else | ||
| 752 | + if (ctx->debug) { | ||
| 753 | + fprintf(stderr, "This function isn't supported on your platform\n"); | ||
| 754 | + } | ||
| 755 | + errno = ENOTSUP; | ||
| 756 | + return -1; | ||
| 757 | +#endif | ||
| 750 | } else { | 758 | } else { |
| 751 | errno = EINVAL; | 759 | errno = EINVAL; |
| 752 | return -1; | 760 | return -1; |