readBlocking vs readValues

Looking for best practices advice and make sure I understand my options better.

A PLC updates two specific registers and then latches a trigger bit telling Ignition data is ready to be stored in the database. I want to guarantee I get the correct data. Is it better to use system.tag.readBlocking or system.opc.readValues to accomplish this?

In sticking with best practices is it better to do this on a value changed script on the tag or create a gateway tag change event?

Thanks in advance.

Gateway tag change event, by a country mile.
You must not run blocking operations in value change scripts - they're run on a built-in pool with only three threads by default and expect to complete ~instantly.

You must use system.opc.readValues() to get everything other than the trigger deterministically. system.tag.readBlocking() does not reach out to the PLC--it simply grabs the latest delivered value(s), which may have been read before the trigger change.

And, since system.opc.readValues() can stall thread for a substantial time, it is not safe to use in tag events (on the tag).

So the general idea is create a gateway tag change event, compile the list of tags I want to read, and then use system.opc.readValues() to get them? Will system.opc.readValues wait to get the values before I erase the PLC tags?

# Gateway tag change script
system.opc.readValues(itemPaths=itemPaths)

system.db.runNamedQueries(projectName, nameQueryPath, params)

system.tag.writeBlocking([tagPaths], [0, 0, 0])

Is it safe to use writeBlocking in the gateway tag change script then?

Or stick with system.opc.writeValues?

system.opc.readValues() doesn't take a list of tags. It takes a list of OPC Item Paths. I find it helpful (and most performant) to simply not have Ignition tags at all for the OPC items retrieved with .readValues().

I don't recommend wasting bandwidth wiping all of the read values. Simply use an incrementing integer or microsecond timestamp trigger, and echo the latest completed trigger value to a paired PLC tag as the acknowledgement. The PLC should look for trigger==echo to know that it can write a new payload.

It doesn't much matter whether you use system.opc.writeValues() or system.tag.writeBlocking() to perform the echo. (I would not use system.tag.writeAsync().)