Vision 8.0.9 Tag Writing Buffering Commands

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?

Thanks

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):
system.tag.write(event.source.parent.TagPath,1)

When your using system.tag.write to write to the PLC it doesn’t go to the PLC right away. It goes to the tag. Then when your tag scans again it will write to the PLC. If you are trying to go to the PLC at a set time you should use system.opc.writeValue(). Even using that though you will still need to be concerned with the load on your PLC. If you have to many read/write request in the time slice available to the PLC to process it then it will skip something.

Don’t write to a tag. Write directly to the OPC item instead. (system.opc.write*() functions.)

Also consider changing your algorithm. Writing to a PLC boolean and having the PLC unlatch it is prone to race conditions. Avoid having different sources write to the same register. You might find this algorithm more robust:

http://forum.inductiveautomation.com/t/8-0-3-vision-jog-button/27729/5?u=pturmel

1 Like

system.opc.writeValue() works much better then using the tag write. I’m running into an issue where writing seems to be limited to 1 per second. Running without system.opc.writeValue() at 250ms and a print statement. I get 4 prints per second. Running with system.opc.writeValue() I get about 1 print per second. Is this a setting?

system.opc.writeValue isn’t fire-and-forget, it returns the status of the operation. So it takes a bit longer, especially if your device connection is heavily loaded. (Check your gateway device status page for that.)

1 Like