Bit mask (b)
- Last UpdatedSep 28, 2022
- 2 minute read
The bit mask descriptor is used to define a bit mask used to extract bits from a register. The bit mask can be used only with input points of data type 1, 7, 9 or 11. The bit mask does not apply to output points.
The format of the bit mask is:
b=uuvvwwxxyyzz
where uu, vv, ww, yy, and zz each refer to a single bit. A leading zero is required if the referenced bit is less than 10. The low-order bit is 01 and high-order bit is either 16 or 32. Up to 16 bits can be referenced for a 16-bit word (data types 1 and 11) and up to 32 bits can be reference for a 32-bit word (data type 7 and 9).
For example, the bit mask 0307120802 maps the second bit of the original word to the first bit of the new word, the eighth bit to the second bit, the twelfth bit to the third bit, etc. The high-order bits of the new word are padded with zeros if they are not specified.
Example: A single 16-bit register holds the state of four different thermocouples. The first four bits correspond to the first thermocouple; the second four bits correspond to the second thermocouple, and so on. Four different input points with four different bit masks can be used to read the thermocouple states. The first input point uses a bit mask of 04030201 to read the state of the first thermocouple; the second input point uses a bit mask of 08070605 to read the state of the second thermocouple, and so on. If the sixteen-bit word from the Modbus device was or decimal , then the first thermocouple state is interpreted as binary or decimal , the second thermocouple state is interpreted as or decimal , etc.
For four-byte integer values (data types 7 and 9), the bytes for these points are frequently swapped. The bytes can be swapped with the following bitmask:
b=1615141312111009080706050403020132313029282726252423222120191817