MODBUS_SET_BYTE_TIME(3)

πŸ“¦
version 3.1.6 Β· 3 versions
, in debian bookworm

πŸ’– MODBUS_SET_BYTE_TIME(3) πŸ’–

okay bestie, welcome to the libmodbus manual, section 3, and today's main character is modbus_set_byte_timeout β€” the lil function that decides how long you're willing to wait between two bytes of the same message. no cap, it's giving patience issues but make it ✨configurable✨.


✨ NAME ✨

modbus_set_byte_timeout β€” set timeout between bytes 🌸


✨ SYNOPSIS ✨

void modbus_set_byte_timeout(modbus_t *ctx, uint32_t to_sec, uint32_t to_usec);

✨ DESCRIPTION ✨

so basically, modbus_set_byte_timeout() sets the timeout interval between two consecutive bytes of the same message. that's it, that's the vibe. πŸ’…

this timeout is an upper bound on how much time can pass before select() comes back. and if the time that's elapsed is longer than the timeout you defined? yeah, an ETIMEDOUT error gets raised by the function that's sitting there waiting for a response. rip 😭

the to_usec argument must be in the range 0 to 999999. like, that's the rule, respect it. πŸ‘‘

now here's the tea πŸ“ β€” if both to_sec and to_usec are zero, this timeout just... isn't used at all. not even a little bit. in that case, modbus_set_response_timeout() governs the entire handling of the response, which means the full confirmation response has to arrive before the response timeout expires. the whole thing. every byte. no pressure bestie. 🌈

but when a byte timeout is set, the response timeout is only used to wait for the first byte of the response. after that, the byte timeout takes over. it's giving tag-team energy. 🫢


✨ RETURN VALUE ✨

the function shall return 0 if it's successful β€” slay. otherwise it shall return -1 and set errno. not slay. πŸ’€


✨ ERRORS ✨

  • EINVAL β€” the argument ctx is NULL or to_usec is larger than 1000000. so, either you forgot to hand it a context (bestie, where is it 😭) or your microseconds went feral and exceeded the limit. >1000000 is a no from the function, respectfully.

✨ SEE ALSO ✨

go read those too, they're the friend group. πŸ‘‘


✨ AUTHORS ✨

the libmodbus documentation was written by StΓ©phane Raimbault <stephane.raimbault@gmail.com> β€” thank you for your service, icon πŸŽ€


libmodbus v3.1.6 Β· 11/17/2025 β€” okay that's a wrap bestie, go set some timeouts responsibly, mwah πŸ’œβœ¨πŸ¦‹

πŸ“¦ where this page comes from