Problem: How can I access multiple bits from an integer item and treat their combined values as a single entity? |
Solution: Create an alias (see the Alias Configuration section of the user’s guide for more information on Aliases) that references the desired OPC item and configure scaling for the alias to use expression evaluation. Edit the input expression to use binary math to access the combined bits as follows:
Edit the input expression using the following format:
DIV(INPUT AND Bitmask,RelativeOffset) or
(INPUT AND Bitmask) * RelativeOffset
For example, suppose we wanted to treat bits 6 and 7 of an integer as an OPC item ranging in values from 0 to 3 (two bits are needed to represent values in this range). The expression to do this would be:
DIV(INPUT AND 192,64)
To make this easier to understand, we number the bits 0 to 31 (least to most significant), thus:
value(bit x)=2^x.
The example takes bit 6 of our integer (whose decimal value is 64) and bit 7 (whose decimal value 128) and adds them together (128+64=192) to form the Bitmask part of the expression. It then renders this to a number in the range of 0-3 by dividing by the RelativeOffset (192/3=64). |
|
|
Category: OPC Servers |
|
|