| 1 | # modbus_mask_write_register |
| 2 | |
| 3 | ## Name |
| 4 | |
| 5 | modbus_mask_write_register - mask a single register |
| 6 | |
| 7 | ## Synopsis |
| 8 | |
| 9 | ```c |
| 10 | int modbus_mask_write_register(modbus_t *ctx, int addr, uint16_t and_mask, uint16_t or_mask); |
| 11 | ``` |
| 12 | |
| 13 | ## Description |
| 14 | |
| 15 | The *modbus_mask_write_register()* function shall modify the value of the |
| 16 | holding register at the address 'addr' of the remote device using the algorithm: |
| 17 | |
| 18 | new value = (current value AND 'and_mask') OR ('or_mask' AND (NOT 'and_mask')) |
| 19 | |
| 20 | The function uses the Modbus function code 0x16 (mask single register). |
| 21 | |
| 22 | ## Return value |
| 23 | |
| 24 | The function shall return 1 if successful. Otherwise it shall return -1 and set |
| 25 | errno. |
| 26 | |
| 27 | ## Errors |
| 28 | |
| 29 | - *EINVAL*, the context is NULL. |
| 30 | |
| 31 | ## See also |
| 32 | |
| 33 | - [modbus_read_registers](modbus_read_registers.md) |
| 34 | - [modbus_write_registers](modbus_write_registers.md) |