Script Creating OPC tag, pause, then Read Value back

Hi,
I have seen other posts around how to add delay to a script (don’t use sleep but use getSeconds(Now) then compare to desired delay time). When I create an OPC tag using scripting, it will take let’s say 5 seconds for the value of the tag to be populated from the device. I am writing a script that does the following (high level):

  1. Create OPC tag (system.tag.configure)
  2. Wait 5 Seconds
  3. Get value reading from OPC Tag (system.tag.readBlocking - quantity #)
  4. Use value (quantity #) read above to start creating a sub-set of OPC tags using quantity.

I was thinking of how to do this pause while the script is running so that the script waits for a good value, reads it in, then continues.

I am sure someone came across this issue before.
Any suggestions?

I’m thinking this may be of use.
https://docs.inductiveautomation.com/display/DOC81/system.util.invokeLater

Do you actually need the ‘parent’ tag to exist as a real tag, or do you just need it for the one OPC value?

https://docs.inductiveautomation.com/display/DOC81/system.opc.readValue

What if instead of pausing you just read the value directly (system.opc.read*) and then created all the tags at once.

Edit: Paul beat me to it

I tried this but the invoke later function is only executed at the end of the script. I wanted this to happen as the script is running.
Now… unless i create the opc tag, then use the invoke function to delay 5 second, then run the delayed function of reading back the value and then creating the OPC tags… let me try this again.

You really shouldn’t bother with this approach. It’s flawed and your 5 seconds is just a guess as to when the value might populate. It could take a server longer for any number of reasons.

1 Like

I think this is the path I might take. As i can use system.opc.read to get my configuration values, then use these values to build out my OPC tag structure. This will work much better than creating a tag, then waiting for good value, then using it. Ill report back!

Nope. In any event routine, if you think you want a delay and then to continue in the same script, you are screwing up. The part after the delay needs to be in a separate function.