---
name: "modbus_mask_write_register"
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_mask_write_register"
---

# modbus\_mask\_write\_register(3)

mask a single register

## NAME

modbus\_mask\_write\_register - mask a single register

## SYNOPSIS

**int modbus\_mask\_write\_register(modbus\_t \****ctx***, int** *addr***, uint16\_t** *and***, uint16\_t** *or***);**

## DESCRIPTION

The **modbus\_mask\_write\_register()** function shall modify the value of the holding register at the address *addr* of the remote device using the algorithm:

```
new value = (current value AND 'and') OR ('or' AND (NOT 'and'))
```

The function uses the Modbus function code 0x16 (mask single register).

## RETURN VALUE

The function shall return 1 if successful. Otherwise it shall return -1 and set errno.

## SEE ALSO

[**modbus\_read\_registers**(3)](/modbus_read_registers/3.md) [**modbus\_write\_registers**(3)](/modbus_write_registers/3.md)

## AUTHORS

Martijn de Gouw \<martijn.de.gouw@prodrive.nl\> The libmodbus documentation was written by Stéphane Raimbault \<stephane.raimbault@gmail.com\>
