Main Content
maskWrite
Perform mask write operation on a holding register
Description
maskWrite(m,
writes data to Modbus object address
,andMask
,orMask
)m
to a holding register at address
address
, using the indicated mask values. The function can
set or clear individual bits in a specific holding register. It is a
read/modify/write operation, and uses a combination of an AND mask, an OR mask, and
the current contents of the register.
Examples
Input Arguments
Tips
The function algorithm works as follows:
Result = (register value AND andMask) OR (orMask AND (NOT andMask))
For example:
Hex Binary Current contents 12 0001 0010 And_Mask F2 1111 0010 Or_Mask 25 0010 0101 (NOT And_Mask) 0D 0000 1101 Result 17 0001 0111
If the orMask
value is 0, the result is simply the logical ANDing of the current contents and the andMask
. If the andMask
value is 0, the result is equal to the orMask
value.