Tag.write vs opc.write

Hello,
there are two writes for tag. system.tag.write and system.opc.write. Whats the difference? is OPC one faster than tag write? What should be used and why and when.

thanks

They don't both write to tags. system.tag.write* does write to tags, of course, but system.opc.write writes directly to the OPC server (bypassing the tag system altogether). system.opc.write can be used to write to PLC tags that don't have an associated Ignition tag.

I wrote system.tag.write* because in 8.1 you should use either system.tag.writeBlocking or system.tag.writeAsync. "Blocking" will pause your script until the write has been accomplished and will return a list of quality codes that you can examine to verify the write was successful. "Async" is fire and forget. The work happens in a separate thread, returns nothing, and your script continues on immediately. I believe that system.tag.write (deprecated) works the same as system.tag.writeBlocking, but it isn't recommended for new work.

Edited for accuracy.

Links that may be helpful:

https://docs.inductiveautomation.com/display/DOC81/system.opc.writeValues
https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking
https://docs.inductiveautomation.com/display/DOC81/system.tag.writeAsync

No, the legacy system.tag.write() is asynchronous, and provides no opportunity to ever get the write status.

Modern system.tag.writeAsync() is not fire-and-forget when used with a callback. The callback gets the list of status codes that writeBlocking() would have returned. (IIRC, under the hood, writeBlocking() is really a writeAsync() that waits on the callback.)

The legacy equivalent to writeBlocking was writeSynchronous().

1 Like

Coming into this thread with a question - both write at the moment of calling correct? I.e. system.tag.writeBlocking does not wait until the next polling opportunity to try to write, it writes the moment it's called correct and the only differences are the ones mentioned above in this thread?

Yes, that's correct.

edit: ish. You can treat it that way, though technically there can be a slight delay that has nothing to do with polling or tag group rates. But since you are blocking and awaiting the result of the write it doesn't matter.

1 Like