MODBUS_RECEIVE(3)

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

πŸ’– MODBUS_RECEIVE(3) πŸ’–

okay bestie, welcome to the libmodbus manual β€” yes it's a real manual, yes it's for the C library, and yes we're gonna make it cute. this one's all about modbus_receive, and it's genuinely one of the most iconic functions in here. let's get into it 🫢


✨ NAME ✨

modbus_receive β€” receive an indication request

🌸 SYNOPSIS 🌸

int modbus_receive(modbus_t *ctx, uint8_t *req);

πŸ’… DESCRIPTION πŸ’…

so the modbus_receive() function shall receive an indication request from the socket of the context ctx. that's the whole vibe. ✨

this function is the one the Modbus slave/server uses to receive and analyze indication requests that the masters/clients send over. like, the server is just sitting there being gorgeous and this is how it hears what the clients are asking for. no cap. πŸ‘‘

if you need to use a different socket or file descriptor than the one defined in the context ctx, go look at modbus_set_socket(3) β€” that's the one that lets you swap the socket out. πŸ’«

πŸŽ€ RETURN VALUE πŸŽ€

on success, the function shall store the indication request in req and return the request length. slay. πŸ“

but here's the lil plot twist: the returned request length can be zero if the indication request is ignored β€” for example, a query for another slave in RTU mode. it's giving "not my business, not my problem." πŸ™ˆ

otherwise it shall return -1 and set errno. so if you see that -1, check your errno, bestie. 😭

fr fr, don't ignore that errno. it's literally the only clue you get.

πŸ”₯ SEE ALSO πŸ”₯

πŸ‘‘ AUTHORS πŸ‘‘

the libmodbus documentation was written by StΓ©phane Raimbault <stephane.raimbault@gmail.com> β€” absolute legend, main character energy, we stan. πŸ’œ


and that's the whole page, bestie! this was libmodbus v3.1.6, dated 11/17/2025 β€” periodt. πŸ’…βœ¨ πŸ¦‹

πŸ“¦ where this page comes from