Hello, I have problem my scripts do not run as expected or don't run at all. I need to delay script execution in Tag Event Scripts > Value Changed. The purpose is just to simulate the PLC feedbacks for while connected to the built-in Programmable Device Simulator.
This code is working but no matter how much the delay in timer it is always run immediately:
I know there may be better approaches to what I need to do, but I really need to know how to make this approach work. Also, I am restricted to use the built-in Programmable Device Simulator, no PLC simulator or external scripting.
Hope script experts can help. Thanks in advance.
I already tried it but also failed for two reasons, first, InvokeLater scope is only Vision Client, and second, the "[.]Run_FB" causes error if used inside a function I don't know why.
Error: LegacyScripting[system_util_tag] 06Mar2023 14:17:30 Error writing tags Error writing to tag '[.]Run_FB': Error_Configuration("Tag provider '.' not found")
In general, any delays of any kind are not acceptable in tag value change scripts, or any other tag event, due to the shared execution thread pool. Don't do it. You will bog down your tag infrastructure.
Instead, design a state machine, perhaps with a timestamp in a memory tag, that is updated by a regular timer event. Do not use jython time, thread, or sleeping functionality in such events (or anywhere in Ignition, really).
Thank you for the advice and link. I already did my search and found the link, but unfortunately I'm a beginner in scripting and couldn't understand how to use the script in the link. Also, I think those methods are not meant to be used in tag value changed scripts. If you have any ideas, please share with use a sample script, I would be grateful.
Thank you for the advice. Sorry for being so ignorant, but I didn't get your solution about building a state machine and how to ramp up and down (simulate) values like pump speed, valve position and flow conditionally according to other tags in the UDT. Let's say I want the Pump speed to ramp up from 0 to 1500 once the run feedback back tag change from False to True. And vice versa when the feedback change to false. If you may share a small sample with us I would be grateful.