|
@@ -968,7 +968,7 @@ int modbus_rtu_get_serial_mode(modbus_t *ctx)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int modbus_rtu_set_rts(modbus_t *ctx, int mode)
|
|
|
+int modbus_rtu_get_rts(modbus_t *ctx)
|
|
|
{
|
|
|
if (ctx == NULL) {
|
|
|
errno = EINVAL;
|
|
@@ -978,19 +978,7 @@ int modbus_rtu_set_rts(modbus_t *ctx, int mode)
|
|
|
if (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU) {
|
|
|
#if HAVE_DECL_TIOCM_RTS
|
|
|
modbus_rtu_t *ctx_rtu = ctx->backend_data;
|
|
|
-
|
|
|
- if (mode == MODBUS_RTU_RTS_NONE || mode == MODBUS_RTU_RTS_UP ||
|
|
|
- mode == MODBUS_RTU_RTS_DOWN) {
|
|
|
- ctx_rtu->rts = mode;
|
|
|
-
|
|
|
- /* Set the RTS bit in order to not reserve the RS485 bus */
|
|
|
- ctx_rtu->set_rts(ctx, ctx_rtu->rts != MODBUS_RTU_RTS_UP);
|
|
|
-
|
|
|
- return 0;
|
|
|
- } else {
|
|
|
- errno = EINVAL;
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ return ctx_rtu->rts;
|
|
|
#else
|
|
|
if (ctx->debug) {
|
|
|
fprintf(stderr, "This function isn't supported on your platform\n");
|
|
@@ -998,13 +986,13 @@ int modbus_rtu_set_rts(modbus_t *ctx, int mode)
|
|
|
errno = ENOTSUP;
|
|
|
return -1;
|
|
|
#endif
|
|
|
+ } else {
|
|
|
+ errno = EINVAL;
|
|
|
+ return -1;
|
|
|
}
|
|
|
- /* Wrong backend or invalid mode specified */
|
|
|
- errno = EINVAL;
|
|
|
- return -1;
|
|
|
}
|
|
|
|
|
|
-int modbus_rtu_get_rts(modbus_t *ctx)
|
|
|
+int modbus_rtu_set_rts(modbus_t *ctx, int mode)
|
|
|
{
|
|
|
if (ctx == NULL) {
|
|
|
errno = EINVAL;
|
|
@@ -1014,7 +1002,19 @@ int modbus_rtu_get_rts(modbus_t *ctx)
|
|
|
if (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU) {
|
|
|
#if HAVE_DECL_TIOCM_RTS
|
|
|
modbus_rtu_t *ctx_rtu = ctx->backend_data;
|
|
|
- return ctx_rtu->rts;
|
|
|
+
|
|
|
+ if (mode == MODBUS_RTU_RTS_NONE || mode == MODBUS_RTU_RTS_UP ||
|
|
|
+ mode == MODBUS_RTU_RTS_DOWN) {
|
|
|
+ ctx_rtu->rts = mode;
|
|
|
+
|
|
|
+ /* Set the RTS bit in order to not reserve the RS485 bus */
|
|
|
+ ctx_rtu->set_rts(ctx, ctx_rtu->rts != MODBUS_RTU_RTS_UP);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ errno = EINVAL;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
#else
|
|
|
if (ctx->debug) {
|
|
|
fprintf(stderr, "This function isn't supported on your platform\n");
|
|
@@ -1022,24 +1022,23 @@ int modbus_rtu_get_rts(modbus_t *ctx)
|
|
|
errno = ENOTSUP;
|
|
|
return -1;
|
|
|
#endif
|
|
|
- } else {
|
|
|
- errno = EINVAL;
|
|
|
- return -1;
|
|
|
}
|
|
|
+ /* Wrong backend or invalid mode specified */
|
|
|
+ errno = EINVAL;
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
-int modbus_rtu_set_rts_delay(modbus_t *ctx, int us)
|
|
|
+int modbus_rtu_set_custom_rts(modbus_t *ctx, void (*set_rts) (modbus_t *ctx, int on))
|
|
|
{
|
|
|
- if (ctx == NULL || us < 0) {
|
|
|
+ if (ctx == NULL) {
|
|
|
errno = EINVAL;
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
if (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU) {
|
|
|
#if HAVE_DECL_TIOCM_RTS
|
|
|
- modbus_rtu_t *ctx_rtu;
|
|
|
- ctx_rtu = (modbus_rtu_t *)ctx->backend_data;
|
|
|
- ctx_rtu->rts_delay = us;
|
|
|
+ modbus_rtu_t *ctx_rtu = ctx->backend_data;
|
|
|
+ ctx_rtu->set_rts = set_rts;
|
|
|
return 0;
|
|
|
#else
|
|
|
if (ctx->debug) {
|
|
@@ -1079,17 +1078,18 @@ int modbus_rtu_get_rts_delay(modbus_t *ctx)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int modbus_rtu_set_custom_rts(modbus_t *ctx, void (*set_rts) (modbus_t *ctx, int on))
|
|
|
+int modbus_rtu_set_rts_delay(modbus_t *ctx, int us)
|
|
|
{
|
|
|
- if (ctx == NULL) {
|
|
|
+ if (ctx == NULL || us < 0) {
|
|
|
errno = EINVAL;
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
if (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU) {
|
|
|
#if HAVE_DECL_TIOCM_RTS
|
|
|
- modbus_rtu_t *ctx_rtu = ctx->backend_data;
|
|
|
- ctx_rtu->set_rts = set_rts;
|
|
|
+ modbus_rtu_t *ctx_rtu;
|
|
|
+ ctx_rtu = (modbus_rtu_t *)ctx->backend_data;
|
|
|
+ ctx_rtu->rts_delay = us;
|
|
|
return 0;
|
|
|
#else
|
|
|
if (ctx->debug) {
|