I have an event driven query tag that runs when it gets an ID from another tag. Issue is the event sometimes executes before the entry has actually been made in the database, so it will return null. Manually running the query again immediately after will return the desired result.
Is there a clean solution to this? Obviously I could make it a fixed rate query tag but this ID only changes once every week or so, so refreshing the query every second would be overkill. Thanks in advance.
You could change your query tag to a memory tag. Create a gateway tag change script that looks at the id tag. If the value changes, run the query, and write the result to the memory tag.
Thanks for the answer dk. Though wouldn't this run into the same issue if the query in the change script returns null also?
Maybe I misunderstood on first read. Is the process of inserting the ID into the database on change the thing you are waiting for?
What is the sequence of events for inserting the ID into the db?
The ID is generated on the PLC, after which it begins the process of making an entry in the database. My tag is looking for the ID on the PLC, so it often picks it up before the corresponding entry is made in the DB.
How about a gateway timer script set for 5s that checks if the dataset memory tag is null? If it is null and there is a value in the ID tag, it polls the database for the record. If it gets a record back, it places it in the memory tag, if not, it leaves it null. If there is data already in the tag then the script can just exit there.
Combine this with a tag change event that writes null to the dataset memory tag on ID value change.
Thanks for the suggestion ryan. I'll probably go with a solution in this direction if there isn't a way to avoid something constantly running on a timer.
The only other way would to be use a Gateway Tag Change event that would spawn a long lived thread that would retry for a value at a set rate, then would stop itself once it got a value (or hit a hard set timeout or received a shutdown command).
What is generating the record in the db? Another script or a transaction group in Ignition?
2 Likes
I like that idea too, thanks. And it's a system external to Ignition that's generating the DB records so not much can be done on that side of things.
I ended up going with another solution that seemed to do the trick - I set the query tag to Fixed Rate with an Execution Time of 0ms & added a change script to the ID tag that reconfigures the query tag's Execution Time to 5000ms. Once the query tag picks up a non-null value it changes its Execution Time back to 0ms.
Might not be best practice to be regularly reconfiguring tags on change scripts but it seems to be working just fine.