MODBUS_WRITE_BITS(3)

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

πŸ’– MODBUS_WRITE_BITS πŸ’–

okay bestie, so this one lives in the libmodbus Manual and it's literally the "set a whole bunch of coils at once" girlie. no cap. let's get into it 🫢


✨ NAME ✨

modbus_write_bits β€” write many bits 🌈


πŸŽ€ SYNOPSIS πŸŽ€

int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *src);

πŸ’… DESCRIPTION πŸ’…

so the modbus_write_bits() function shall write the status of the nb bits (coils) from src at the address addr of the remote device. that's the whole vibe, bestie β€” you're yeeting a whole pile of coil states at the remote device in one go instead of doing it one by one like a peasant. πŸ‘‘

and listen, the src array must contain bytes set to TRUE or FALSE. that part is non-negotiable, it's giving "do not freestyle this". πŸ’€

under the hood? the function uses the Modbus function code 0x0F (force multiple coils). iconic. main character energy fr fr. ✨


⭐ RETURN VALUE ⭐

if everything slays, the function shall return the number of written bits. cute, we love a receipt. πŸ’–

otherwise? it shall return -1 and set errno. 😭 that's your cue to do a vibe check on your inputs.


πŸ¦‹ ERRORS πŸ¦‹

  • EMBMDATA β€” writing too many bits 🚨
bestie when this hits you were being way too ambitious with nb. the remote device said "no thank you ma'am." πŸ™ˆ

🌸 SEE ALSO 🌸


πŸ‘‘ AUTHORS πŸ‘‘

the libmodbus documentation was written by StΓ©phane Raimbault <stephane.raimbault@gmail.com> πŸ’œ shoutout to the legend, we stan.


and that's the page, bestie!! this doc came to you courtesy of libmodbus v3.1.6, dated 11/17/2025 β€” periodt πŸ’…βœ¨

πŸ“¦ where this page comes from