I wanted to cache some tag values that are basically set once via query when Ignition starts, cache them inside a script library's variables like this:
TAG1 = system.tag.readBlocking('path')[0].value
so then I can refer to that instead of having to read the tag each time I need it in a script
project.util.TAG1
However, just recently the GW had a patch update applied and it rebooted, and scripts that were using the value were failing due to TAG1 being None.
I assume that this is because when it rebooted, the tag system wasn't up yet before the scripting system was and before the library had initialised, hence the None value trying to read the tag that wasn't there yet. Is this correct?
What would be the best way to resolve this? For now I'm just going to use a dreaded while with time.sleep to check if it's null and keep reading it until it isn't
I figure a sleep at such an early once off init stage isn't going to have an effect
Instead of reading the variable, call a function, the function can simply check that the value isn’t 'None' and return the top level variable value, or if it is, read the tag, set the variables value, and then return.
This way you essentially have the same processing time, but can read the tag if needed.
Can someone explain why print project.util.TEST2 isn't equal to Hello2? and why print project.util.getTest3() isn't equal to 'Hello3'? and both test 4's result in None?
I normally like to include the full library references to make finding things simpler... but maybe I shouldn't be doing that??
I also think maybe I should be using system.util.getGlobals() instead of module variables