4 mask write register, Mask write register – In-Situ Aqua TROLL 400 Modbus and SDI-12 Reference Guide User Manual
Page 61

Where Byte Count is the #bytes in the Data Payload (does not include CRC bytes).
Byte Count = 2*Register Count.
The register count is limited to a single data format field. If an attempt is made to write a data
field with an incorrect register count, the device will return a Modbus exception response with
error code 0x80.
8.10.4
Mask Write Register
This command will set and/or clear one or more bits in a single register.
Message :
Response:
Address
1 Byte
1-247
Address
1 Byte
1-247
Function Code
1 Byte
0x16
Function Code
1 Byte
0x16
Data Address
2 Bytes
0 to 0xFFFF Data Address
2 Bytes
0 to 0xFFFF
And_Mask
2 Bytes
0 to 0xFFFF And_Mask
2 Bytes
0 to 0xFFFF
Or_Mask
2 Bytes
0 to 0xFFFF Or_Mask
2 Bytes
0 to 0xFFFF
CRC
2 Bytes
CRC
2 Bytes
Register = (Register Value AND And_Mask) OR (Or_Mask AND (NOT And_Mask))
And_Mask: 0 = bits to change, 1 = bits to leave unchanged.
Or_Mask: 0 = bits to clear, 1 = bits to set.
Example: - set bit 1 (LSB), clear bit 2, leave remaining bits unchanged
Old Value:
0x007E
0000 0000 0111 1110
And_Mask:
0xFFFC
1111 1111 1111 1100
Or_Mask:
0x0001
0000 0000 0000 0001
New Value:
0x007D
0000 0000 0111 1101
This command is useful in a bit mapped register where the Master wants to set some bits of a
register that are mapped to a feature without disturbing the other bits of the register that might
be mapped to a different feature.
61