Using Jython I’ve been able to check if a button is pressed. I have a timer component that checks every 250ms to see if the button is pressed. Every 250ms the actionPerformed scripts run, checking if the button is pressed and then writes a 1 to a boolean tag X using system.tag.write.
The scan class of the tag is Mode: direct, Data Mode: Subscribed, and Rate: 100.
The PLC logic is when X is on increment a counter and turn off X.
When I press the button the timer script starts writing to the PLC and my counter increases. When the button is released the timer continues to write to the PLC as if the button was pressed. This happens for some amount of time that increases with how long I have the button pressed for.
I’ve also noticed that on the PLC side the writes for Tag X sometimes come in for almost double the time of the timer. So if the timer is running every 250ms I might have a gap of 600ms where I do not see a tag write from the PLC side. I’ve tried increasing the timer to happen every 1000ms then on the PLC side I might not see a write for 2200ms.
My theory is that Ignition is not executing the writes as they are called but buffer the writes and processes them at a later time. Which would explain why holding the button down longer increases the period of tag writes after releasing the button to extend.
Is there a way to change this behavior to actually write the value of 1 to tag X when the button is pressed at the timer rate and to stop writing when the button is released?
Code for Checking Button State
from javax.swing import JButton
from javax.swing import SwingUtilities
comp = event.source.parent.getComponent(“Momentary Button”)
button = SwingUtilities.getAncestorOfClass(JButton, comp)
if(comp.getModel().isPressed() and system.tag.read(event.source.parent.TagPath).value == 0):