Add delay between tag writes in a gateway script

I have a gateway tag event script that when triggered, populates Tag A with a value, and then triggers tag B Boolean for another system to read it.

The issue I am running into is that even though I am using writeBlocking, the tag A isn't updating fast enough and when Tab B boolean is triggered, Tag A is still showing the previous value when its read.

I validated this using time.sleep with a 1 second delay. I know Time.sleep is frowned upon, what do you recommend using to delay between two tag writes by 500ms or 1s?

I saw an older post where they created a while loop in between, passed in the current time and it exited after 1 sec had passed but that doesn't feel write (Pun intended).

Any suggestions? Thanks!

Are these OPC tags?

If so, then the easiest path would be to use system.opc.writeValue and system.opc.ReadValue instead of system.tag.read/write.

This will ensure that you are getting the actual value from the PLC outside of any scan class timing issues you might be seeing.

When you say another system reading it, how is that system connected? Does it read from the Ignition Tag or the PLC?

There are Ignition memory tags and the other system is connected through an exposed tag provider, it watches the boolean to go true and then reads the value tag. I will try the opc read and see how it goes. Thanks

If they are memory tags than OPC won't work.

I am having a hard time understanding why a memory tag write would not be immediately available with the new value being written though.

What type of scan class do you have the memory tag on?

Can you add the delay inside the other system (presumably a PLC)? "Other system" sees the boolean change, waits, then reads the value you're wanting it to read?

Another question, why do it this way at all? Just have the other system store the previous value on change and then do whatever you're wanting to do.

The other system is waiting on the boolean tag to go true before reading the value tag. Unfortunately I cant change that functionality or that system.

In an ideal world, using writeBlocking to update the value tag and then setting the boolean True should work fine. Not sure why its happening too fast and not getting the updated value. Like I mentioned in the post, if I set a delay of 1 second, it works perfect.

Support mentioned using invokelater or invokeAsync to create a small delay but I haven't tried those solutions yet.

if you have to do time.sleep I recommend creating a function and running it through system.util.invokeAsynchronous so that its running on a separate thread. Ideally you would want to send the update to tag A then have a tag event change script on tag A run the rest.

I was trying to avoid time.sleep if possible but wrapping it an invoke might work. I have some testing to do

Make Tag B an expression tag:
millisBetween({[.]TagA.Timestamp}, now()) >= 1000

The hard-coded max update rate of remote tag providers is 1s, so this might be your issue here. I don't know if it will help, but what if you write both tags at once?

When using an exposed tag provider, you are at the mercy of the other side's subscription pace, and the fact that subscription delivers have no guaranteed order. If the other side is not doing a subscription for the boolean, then a polled read for the updated value, then you will always need a delay to ensure their side's update paces expires between the two writes.