Is it possible to read the bit of an OPC Tag set as an integer?
I want to read an individual bit off a DINT tag pulled from a PLC in scripting, without having to break the tags into individual Igniton tags.
Is it possible to read the bit of an OPC Tag set as an integer?
I want to read an individual bit off a DINT tag pulled from a PLC in scripting, without having to break the tags into individual Igniton tags.
There 's an expression function getBit…
If you want in scripting, look here…
def getbit(x,n):
"Get the n-th bit of the number x"
return x & (1 << n) and 1 or 0
Explanation: x & (1 << n) means bitwise AND between x and 2^n. And the expression P and 1 or 0 means: if P then return 1, otherwise return 0.
And this works for numbers of any size. Python is not limiting you to 32 bit integers.