Commit cf6449145a13f53aef969e89599be86f888539f3

Authored by Habu
Committed by Stéphane Raimbault
1 parent 541804b3

Calculate RTS activation time by send length

src/modbus-rtu-private.h
... ... @@ -81,6 +81,7 @@ typedef struct _modbus_rtu {
81 81 #endif
82 82 #if HAVE_DECL_TIOCM_RTS
83 83 int rts;
  84 + int onebyte_time;
84 85 #endif
85 86 /* To handle many slaves on the same link */
86 87 int confirmation_to_ignore;
... ...
src/modbus-rtu.c
... ... @@ -296,7 +296,7 @@ ssize_t _modbus_rtu_send(modbus_t *ctx, const uint8_t *req, int req_length)
296 296  
297 297 size = write(ctx->s, req, req_length);
298 298  
299   - usleep(_MODBUS_RTU_TIME_BETWEEN_RTS_SWITCH);
  299 + usleep(ctx_rtu->onebyte_time * req_length + _MODBUS_RTU_TIME_BETWEEN_RTS_SWITCH);
300 300 _modbus_rtu_ioctl_rts(ctx->s, ctx_rtu->rts != MODBUS_RTU_RTS_UP);
301 301  
302 302 return size;
... ... @@ -1060,6 +1060,9 @@ modbus_t* modbus_new_rtu(const char *device,
1060 1060 #if HAVE_DECL_TIOCM_RTS
1061 1061 /* The RTS use has been set by default */
1062 1062 ctx_rtu->rts = MODBUS_RTU_RTS_NONE;
  1063 +
  1064 + /* Calculate estimated time in micro second to send one byte */
  1065 + ctx_rtu->onebyte_time = (1000 * 1000) * (1 + data_bit + (parity == 'N' ? 0 : 1) + stop_bit) / baud;
1063 1066 #endif
1064 1067  
1065 1068 ctx_rtu->confirmation_to_ignore = FALSE;
... ...