Bit in double integer

Dear experts,

I have a window where i added a custom property to link to a data type.
This data type consists of one “CMD” which is a doubleinteger DI0 to be precise.

Now this window will be my main sequence example and I’m trying to add a button that will set a bit in this double integer tag.

I’ve done some research and I have found a few examples but they won’t work for me. Do any of you see what I’m doing wrong in my scripting?

def setBit(value, position, newValue):
   newValue = (newValue & 1) << position
   mask = 1 << position
   return (value & ~mask) | newValue   

system.tag.write(setBit("event.source.parent.DATA_Sequentie.CMD",0,1))

Thanks in advance this will help me a lot!

These work for integers of any size, even greater than 32 bit:

def set_bit(value, bit):
    return value | (1<<bit)

def clear_bit(value, bit):
    return value & ~(1<<bit)

value = event.source.parent.DATA_Sequentie.CMD
value = set_bit(value,1)
event.source.parent.DATA_Sequentie.CMD = value

#or

event.source.parent.DATA_Sequentie.CMD = set_bit(event.source.parent.DATA_Sequentie.CMD,1)

In the linked custom property you must check Bidirectional…

I found this here:wink: