logo

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Natanael Lira  
#1 Posted : Friday, April 26, 2019 10:47:25 AM(UTC)
Natanael Lira

Rank: Newbie

Joined: 4/26/2019(UTC)
Posts: 1

Hello. I'm needing help to create a mask in a 16 bit word. I can not do the syntax.

I need to isolate the data from the first 8 bits.
I used this syntax.
IF ([UG1-M11.4:1181] & 255 == 255,1,0)
It is returning 1, but should return 0, because in the first 8 bits the data is 0000.0000.


OPC Manual Help

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

Solution: In order to do this, users will have to apply a mask to the value, which will null all of the bits in the integer value except the one that users want to keep.
For example, if the user wanted to isolate the third bit, they would have to apply a mask that is in binary which will only have the third bit present. In binary, this is the number 4 (0100).
To apply the mask, users must use the AND operator, which will leave a 1, if and only if, both the bits in that position are 1.
0110 1100
+ 0000 0100
= 0000 0100

In decimal notation, this would be expressed as 108 AND 4 = 4.
To do this in an OPC server, users would configure an Alias to use the IF operator. With the example above, where the user wishes 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.
Offline Roger Fortune  
#2 Posted : Tuesday, May 28, 2019 8:27:27 PM(UTC)
Roger Fortune

Rank: Advanced Member

Joined: 10/21/2014(UTC)
Posts: 105

Was thanked: 35 time(s) in 32 post(s)
Can you please explain what "UG1-M11.4:1181" is please? Is this a single tag or two tags you are trying to subtract from each other?
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Matrikon Subscribe  |   Matrikon Unsubscribe  |   Global Unsubscribe  |   Privacy Statement  |   Your Privacy Choices   |   Cookie Notice