Commit cf6449145a13f53aef969e89599be86f888539f3
Committed by
Stéphane Raimbault
1 parent
541804b3
Calculate RTS activation time by send length
Showing
2 changed files
with
5 additions
and
1 deletions
src/modbus-rtu-private.h
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; | ... | ... |