The Flow Total tag has an integer in it (35) and the Flow Total Holding tag is a memory integer tag.
the time comes and goes but I still have a null value in the Flow Total Holding tag. It should have written the value from Flow Total to Flow Total Holding. Am I missing something?
Note the sets of [ ] enclosing the tag(s) and arguement(s).
Tip: select your text and press the </> button to format your code as code. It will preserve indentation and apply syntax highlighting. Use the pencil icon on your post to edit and fix it. Use the preview pane to check your post before submitting it.
This code did not work, but what was supplied by Transistor worked perfectly, thanks guys! Didn't know about the script console, that will make testing much faster. Thanks for the quick responses!
Well, be aware that the script console is not in gateway scope, and many system.* functions behave differently than in gateway scope or in Perspective. Each function's documentation explains the differences. (Designer scope is a variation of Vision Client scope.)
Checking again this morning and my script does not work. I am trying the logger as Carlos suggested, but it gives me an error of: name 'myevent-debug' is not defined. Here is my full code I'm putting in console:
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'myevent' is not defined
When a change is made to the Gateway Events scripting, does the application need to be saved everytime? I have tried doing it and not. Wondering what else could have changed..?
Also, you are definingonScheduledEvent() but not calling it. Just def does not cause execution.
Finally, you cannot expect scripts run in the designer's script console to behave the way the script will in gateway scope (the actual event). The designer runs a variation of Vision Client scope and cannot be made to run as if gateway scope.
Thanks for the help guys. Wanted to share what I ended up doing. This helps me to keep up with the long tag arrays much easier. Another thing, once you make changes to the Gateway Event Scripts, you have to save the project. That was a big part of my problem. You don't have to specify ".value" for OPC tags but you do for expressions, so I do it on all.
def onScheduledEvent():
r1 = "[default]Plant PLC/Distribution/Flow/Flow Total Today"
r2 = "[default]Plant PLC/Influent/Flow/Flow Total Today"
r3 = "[default]Plant PLC/Chemical/Caustic/Flow/Flow Total Today"
r4 = "[default]Plant PLC/chemical/HMO/Flow/Flow Total Today"
pathsRead = [r1, r2, r3, r4]
w1 = "[default]Plant PLC/Distribution/Flow/Flow Total Yesterday"
w2 = "[default]Plant PLC/Influent/Flow/Flow Total Yesterday"
w3 = "[default]Plant PLC/Chemical/Caustic/Flow/Flow Total Yesterday"
w4 = "[default]Plant PLC/chemical/HMO/Flow/Flow Total Yesterday"
pathsWrite = [w1, w2, w3, w4]
valuesRead = system.tag.readBlocking(pathsRead)
valuesWrite = [valuesRead[0].value, valuesRead[1].value, valuesRead[2].value, valuesRead[3].value]
system.tag.writeBlocking(pathsWrite, valuesWrite)
I'm not sure what you mean by this. It doesn't matter if you read the value from an OPC tag or an Expression tag, readBlocking() returns a list of qualified values and to get just the value of an item you always need to use .value
I would definitely write this write this differently though.
def onScheduledEvent():
tagPaths = [
"[default]Plant PLC/Distribution/Flow/Flow Total Today",
"[default]Plant PLC/Influent/Flow/Flow Total Today",
"[default]Plant PLC/Chemical/Caustic/Flow/Flow Total Today",
"[default]Plant PLC/chemical/HMO/Flow/Flow Total Today"
]
system.tag.writeBlocking([path.replace('Today','Yesterday') for path in tagPaths], [total.value for total in system.tag.readBlocking(tagPaths)])
In a tagpath, whether read from an expression ({path/to/tag}) or a script (system.tag.read*("path/to/tag")), you do not need to append .valueto the tag path. It is assumed that if you are targeting any discrete (not a folder or UDT instance) tag, you want to read the .value property unless you specify some other property (path/to/tag.engUnits, for instance).
In all cases, reading a tag returns a qualified value object.
In expressions, qualified values are automatically "unwrapped" - the quality is used in the internal evaluation of expression functions, but the actual user code you write will always deal with 'bare' values.
In scripting, we can't make assumptions for you, so reading a tag will always return a (list of) qualified value(s). The modern, idiomatic system.tag.readBlocking function in particular will unconditionally return a list of qualified values that must be unpacked to be used.