info@matrikonopc.com Read More
 
 
  Overview
  Support Options
  Annual Maintenance
  Knowledge Base
  Ticket Tracking
  Support Contact
MatrikonOPC Driver Search
Click below to begin your MatrikonOPC Driver Search.
MatrikonOPC Driver Search
  0 item(s) in your cart.
Total: $0.00 Checkout

General

 

Problem:
How can I access individual bits from an integer item?

Solution:

In order to do this, you will have to apply a “Mask” to the value, which will null all the bits in the integer value except the one that you want to keep.

For example, If you wanted to isolate the third bit, you would have to apply a mask that, in binary, will only have the third bit present. In Binary, this is the number 4 (0100)

In order to apply the mask, you must use the AND operator, which will leave a 1 if and only if both the bits in that position are 1.

0110 1100  <= Data coming in
+
0000 0100  <= Mask
--------------------
0000 0100 <= Result

*note* the highlighted number is the data bit we wish to access

In decimal notation, this would be expressed as 108 AND 4 = 4.

In order to do this in an OPC Server, you would configure an alias to use the IF operator. With the example above, where you wish to access the third bit in the integer, the statement would appear as: 

IF(INPUT And 4 = 4, 1, 0)

Therefore, if the bit in position 3 is a 1, since 1 AND 1 =1, the IF statement would be true and would return a 1. If the bit in position is 0, 0 AND 1 = 0, the IF statement would return a false value, which is a 0.


Category:
OPC Servers




           

 
 

© Matrikon Inc. 2008
Home | Search | Site Map | Privacy Policy | Terms Of Use | Contact