OPC writeValues Async

Hi,

I am looking to use the system.opc.writeValues function, but I would like it to be asynchronous like the system.tag.writeAsync function. Is there an easy way to do this in Ignition?

Thanks in advance!

No, the closest thing would be to fire off the writes inside system.util.invokeAsynchronous, but you need to be careful with that kind of thing.

What precautions would you recommend? I have a large number of OPC tags to write (in an array) so it currently freezes the GUI for an unacceptably long time, so this seems to be the only solution

That might be an okay place to use it, especially since it's being invoked from the GUI instead of e.g. in response to events or in a loop where it might happen more than you think.

What you need to be careful of is making sure that you don't end up with more and more of these threads running in the background.

Sounds like Vision? If so, also be sure to not write to any UI properties or call any UI methods from such a background thread. Use system.util.invokeLater() and friends to send information/progress back to the foreground. Failure to follow this rule will eventually yield mysterious client crashes or unending freezes.

More info:

(Still relevant for Vision.)

What you need to be careful of is making sure that you don't end up with more and more of these threads running in the background.

Is there a way to check if the process is running already? I know with the Qt threading libraries you can name the threads and then query the system to see if they are running to make sure you don’t double up, is that possible in a similar way here?

It is possible but somewhat expensive to query threads yourself.

If this within Vision scope, you could use system.util.getGlobals to store the actual Thread instance returned by system.util.invokeAsynchronous, and check the state of that thread object before your next execution; it'll be an instance of java.lang.Thread and expose all the methods described here:

Another option would be a global sentinel like a tag (possibly a client tag, if Vision scoped) but there's no true support for locking around tags so it's somewhat more fragile.