---
name: "modbus_write_bits"
section: "3"
platform: "linux"
package: "libmodbus-dev"
version: "3.1.6-2.1"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/modbus_write_bits"
---

# modbus\_write\_bits(3)

write many bits

## NAME

modbus\_write\_bits - write many bits

## SYNOPSIS

**int modbus\_write\_bits(modbus\_t \****ctx***, int** *addr***, int** *nb***, const uint8\_t \****src***);**

## DESCRIPTION

The **modbus\_write\_bits()** function shall write the status of the *nb* bits (coils) from *src* at the address *addr* of the remote device. The *src* array must contains bytes set to TRUE or FALSE.

The function uses the Modbus function code 0x0F (force multiple coils).

## RETURN VALUE

The function shall return the number of written bits if successful. Otherwise it shall return -1 and set errno.

## ERRORS

**EMBMDATA**

Writing too many bits

## SEE ALSO

[**modbus\_read\_bits**(3)](/modbus_read_bits/3.md) [**modbus\_write\_bit**(3)](/modbus_write_bit/3.md)

## AUTHORS

The libmodbus documentation was written by Stéphane Raimbault \<stephane.raimbault@gmail.com\>
