MODBUS_READ_BITS(3)

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

πŸ’– MODBUS_READ_BITS πŸ’–

okay bestie, so this is modbus_read_bits from libmodbus β€” it lives in section 3 of the manual (that's the library-functions section, iykyk) and it's literally the glow-up you need when you wanna peek at a whole lil squad of coils at once. ✨


🌸 SYNOPSIS 🌸

int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like, the modbus_read_bits() function shall read the status of the nb bits (coils, bestie β€” coils!) at the address addr of the remote device. it's giving "hey remote device, spill the tea, what's the vibe on these bits" πŸ’…

the result of reading gets stored in the dest array as unsigned bytes (8 bits each, obviously) set to TRUE or FALSE. no cap.

⚠️ okay now PAY ATTENTION because this part is important: you must take care to allocate enough memory to store the results in dest β€” at least nb * sizeof(uint8_t). if you don't, that's on you and it will absolutely not be cute. 😭

and fun fact, the function uses the Modbus function code 0x01 (read coil status). iconic behavior fr fr. πŸ‘‘


✨ RETURN VALUE ✨

on success, the function shall return the number of read bits. slay. πŸ’š

otherwise it shall return -1 and set errno. not the vibe, but at least it tells you why. πŸ™ˆ


πŸ’€ ERRORS πŸ’€

  • EMBMDATA β€” Too many bits requested. bestie you asked for way too many bits, the request is too big, dial it back. 🫠

πŸŽ€ SEE ALSO πŸŽ€

the whole read-and-write bit family, they're a matched set, obsessed honestly. 🫢


πŸ‘‘ AUTHORS πŸ‘‘

The libmodbus documentation was written by StΓ©phane Raimbault <stephane.raimbault@gmail.com> β€” ty for your service, king. 🫑


and that's the whole page, bestie!! this little masterpiece is from libmodbus v3.1.6, dated 11/17/2025, and honestly? main character documentation energy. go read some coils, stay hydrated, allocate your memory properly, mwah πŸ’…πŸ’–βœ¨πŸŒΈπŸ¦‹πŸŽ€

πŸ“¦ where this page comes from