Events processed all the time in designer mode, not just in "play" mode

I have an event script that runs only in designer “play” mode. How can I get it to run all the time ?

I call a script every second when a window opens. This script reads some tags, manipulates the data and then puts it in dataset which is attached to a powerTable.

I accomplished this by attaching a custom property callled “clock” to the powerTable. This property is bound to the tag “[System]Client/System/CurrentDateTime” so it changes every second.
In the powerTable property change event I wrote:
if event.propertyName == ‘clock’:
#code to create a dataset here and write it to the power table property “Data”

This works great in runtime (click on play button in designer) but I want this to run even if the play button is not pressed, just like some components still work no matter what mode you are in (meter for example).

How can I do this ?

runScript() bindings work all the time.

Thanks… At one point Ignition tech support told us to avoid using runscript(). We had it embedded in a template used all over the place and it caused performance issues or memory issues. I can’t remember which. Is this still the case ?

It is often the cause of performance issues because people use it in expressions or bindings and they end up blocking the scan class or UI.

1 Like

If I used the function system.util.invokeAsynchronous() in my script that gets called by runScript() can I avoid blocking the scan class or UI ?

That doesn’t really make any sense - expressions return something, your runScript call needs to return something, so unless you’re using runScript just to trigger some work to happen that you don’t need a result from it won’t work.

1 Like

If you add custom properties to the table to do all of the tag reading, you could use the runscript binding right on the table data property. Pass the custom properties to your script via runScript args. Return the dataset. Don’t do anything in the script that accesses anything outside the vision client (no tag reads, no database calls, etc).

Your right… I don’t need a return value from runScript(). I am using it to do some work for me on a periodic basis then populate a dataset which then gets displayed in a power table.

What I am trying to do is poll tag values when a client window is shown rather than wait for a tag event.

End goal: generic template for which I can pass a path to a UDT then display all the live tag values converted to local units for the user along with quality and timestamp. Our PLC has SI units and users need to see values in their units of choice. I have all the conversion stuff worked out, just need to figure out how to create a polling script that runs even when designer is not in ‘play’ mode because it makes development easier.

Don’t poll tags (or anything else) in a runScript. Use tag bindings for that.
Don’t execute DB queries in runScript. Use query bindings for that.

Use runScript to execute local code to manipulate data passed to it, returning the manipulated data. If you aren’t using the return value, you are doing it wrong, and possibly dangerously so.

(If you find passing data to your functions in a runScript is annoying, consider the objectScript function from my free Simulation Aids module. It is a bit more free-form.}