You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to use RTU on Raspberry Pi (using 64-Bit Raspberry Pi OS, os-issue 2025-10-01, based on Debian Trixie) I ran into trouble like bad CRC and timeout. Then when watching the RTS signal with an oscilloscope I saw that it was held active around twice as long as it should be, so after the RasPi has sent out a request the RTU is kept active too long, and thus the start of the device's answer is missed.
After looking into the sources I was able to fix that in modbus-rtu.c inside function _modbus_rtu_send be replacing usleep(ctx_rtu->onebyte_time * req_length + ctx_rtu->rts_delay);
with tcdrain(ctx->s); usleep(ctx_rtu->rts_delay);
My guess is that the preceding write(ctx->s, req, req_length) already internally waits until all (or almost all) bytes are transmitted and thus waiting another ctx_rtu->onebyte_time * req_length makes the RTS signal much too long.
Replacing this with tcdrain should IMHO have the same effect if bytes were still buffered on a system, but should return immediately if everything was transmitted already.
Do you agree to this analysis and do you think this is a good solution?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
When trying to use RTU on Raspberry Pi (using 64-Bit Raspberry Pi OS, os-issue 2025-10-01, based on Debian Trixie) I ran into trouble like bad CRC and timeout. Then when watching the RTS signal with an oscilloscope I saw that it was held active around twice as long as it should be, so after the RasPi has sent out a request the RTU is kept active too long, and thus the start of the device's answer is missed.
After looking into the sources I was able to fix that in modbus-rtu.c inside function
_modbus_rtu_sendbe replacingusleep(ctx_rtu->onebyte_time * req_length + ctx_rtu->rts_delay);with
tcdrain(ctx->s);usleep(ctx_rtu->rts_delay);My guess is that the preceding
write(ctx->s, req, req_length)already internally waits until all (or almost all) bytes are transmitted and thus waiting anotherctx_rtu->onebyte_time * req_lengthmakes the RTS signal much too long.Replacing this with
tcdrainshould IMHO have the same effect if bytes were still buffered on a system, but should return immediately if everything was transmitted already.Do you agree to this analysis and do you think this is a good solution?
All reactions