Looking for guidance, first time user.
I have created global modules getBit() and setBit() as below:
def getBit(value, position):
return (value >> position) & 1
def setBit(value, position, newValue):
newValue = (newValue & 1) << position
mask = 1 << position
return (value & ~mask) | newValue
I want to create a pop-up control with Test/Run Start/Stop buttons that uses a single INT tag for control/status
On a pop-up window is there a way to pass a tag to the getBit / setBit global script when I call the pop-up? Is there a placeholder that I can use? I have tried adding a custom property “ControlTag” to the root container of the pop-up then on a button on the mouse released event trying:
app.bit.setBit({Root Container.ControlTag}, 1, 1) but get an error.
Is there a better way to accomplish this?
Why not have 4 SQLTags inside of Ignition that each reference a different Bit inside of that Integer. I believe that would make scripting and project design easier.
Unfortunately I’m communicating with an omron plc using modbus. The omron modbus does not support function 0x02 or 0x16. So I cannot write to bits of a word, and it appears I have to have a write tag and a read tag for bit addresses, which gets ugly pretty quickly when you have a number of toggle type commands.
You could try using system.tag.read:
def getBit(tag, position):
value = system.tag.read(tag).value
return (value >> position) & 1
def setBit(tag, position, newValue):
value = system.tag.read(tag).value
newValue = (newValue & 1) << position
mask = 1 << position
return (value & ~mask) | newValue
mouseClicked:
sTag = system.gui.getParentWindow(event).rootContainer.ControlTag
system.tag.write(sTag, app.bit.setBit(sTag, 1, 1))