Bit calculations and bit in AF Analysis

Hi,

Currently we're facing problem regarding bit calculations (AND, OR, NOT, XOR, etc.). PLC will send the data in the form of a binary bit packed word (16 bits), and I need to find where bit with value 1, in that first 10 sequence.

For example, if I have the bit sequence 11100010110001110010110000010111, then I should know that I need to read the status based on bit in the sequence number 1, 2, 3, and 5.

 

And the second is, if I have value < 4,000,000,000, the bit calculations working fine, but if I have value more than 4,000,000,000, the bit calculations is not working. For example, if I have formula “862,022,950 AND 348”, then the AF Analysis will show me the correct result, which is 260. But if I have formula “4,294,966,695 AND 348”, the AF Analysis will show me wrong result, which is 0, because it should be 260.

 

Kindly need your help regarding this issues.

Thank you

  • Hi Surya,

     

    I'm not totally following what you are trying to do, your example is much more that 16 bits, are you operating on a 16 bit value? the 4,000,000,000 number it very close to what a 32 bit unsigned integer can represent (4,294,967,295). I suspect you are experiencing some kind of truncation, or perhaps uncovered a bug.

     

    Lonnie

  • Hello Surya,

    If I understand correctly, you want to know the index where the high bit is located in Binary string, in this case you can bit mask plugin which helps us to provide the index of high bit. Here I have given the example by considering the PI Tag to show the corresponding digital string of high bit Index. If you require to store only Index then convert the digital tag to Int 32. With this we can leverage to functionality priority can be set in reading sequence of binary string. Please refer the BIt Mask plugin configuration in the below mentioned document.

    Bit Mask Plugin: http://cdn.osisoft.com/interfaces/1637/PI_OPCPluginBitmask_2.3.11.2.docx

     

    Assume a Digital set in PI called (E3Plus) with the below digital states.

     

    State

    State Name

    Prority

    0

    Trip

    16

    1

    warning

    2

    2

    Output A

    3

    3

    Output B

    4

    4

    Input 1

    5

    5

    Input 2

    6

    6

    Input 3

    7

    7

    Input 4

    8

    8

    Motor Current Present

    9

    9

    Ground Fault Current Present

    10

    10

    .10 - Not Used

    11

    11

    .11 - Not Used

    12

    12

    .12 - Not Used

    13

    13

    .13 - Not Used

    14

    14

    .14 - Not Used

    15

    15

    .15 - Not Used

    1

     

    The order of the strings in the digital set is significant, since this must correspond to the priority in which we want  the data to be examined.

    The first bit that is set will be used as the value. In this example, bit 16 representing the Trip bit must be examined first, then bit 2, etc.

     

    If bit 16 is set, then the value 0 is saved to PI and no further data is examined. The value 0 is related with the state string Trip.

    Algorithm won’t proceed further as the priority Bit 16 is present and the value is set in the PI Tag. If Bit 16 is not present then algorithm validates Bit 2 and further as per the priority set.

  • Hi Mike and Lonnie,

    Thank's for the input for the second questions, and after I change the data type from Int32 to Int64, it's working fine. But what I don't understand is, the result of the bit calculations should not over than Int32 range (2147483647 (?)).So why the data type should be change to Int64 ?

  • If you are trying to check the high bits of some input, try using the signed representation instead. For example, if 4294966695 is the value as an unsigned int32, then try using -601 instead. "-601 AND 348" gives your expected result of 260. Note that neither AF, nor Data Archive lets you directly type values as unsigned integers (at least easily).

     

    I suspect that if the literal value doesn't fit into a signed 32-bit integer then it is treated as a double precision floating point value by Analysis. After that I suspect it truncates it when using in the AND operator, but that is just a guess.

  • Hi Surya,

     

    Regarding your first question, an idea would be to create children AF Attributes to see what each bit is giving, either 1 or 0, and then use AF Analysis or Formula to get the necessary information out of the bit sequence. The binary data can actually be coming as a binary string, or as the integer number itself. To extract each bit value from the string, you can use the String Builder data reference with the Mid function like shown below. To extract each bit from an integer value, where each bit can be a separate alarm, you can use a Formula data reference, like the following to extract bit number 3: F=..;[abs(F and 2^2)/2^2].  In the picture, it is shown for bit number 2. Each children attribute could even be associated with an Enumeration Set to translate the 0 and 1 into the specific status name.

     


    Reading+Bits.png.png

    Hopefully this will help out a bit, regards.

  • Hi

    We normally use bit mask plugin functionality which is available in PI OPC DA interface to identify which bit is enabled and then map to a digital state to know the status