Hi guys ,
I’m trying to pass Tags as parameter to a script but it’s not working . Is it possible?
Here is my expression:
runScript("shared.backgroundcolor.backgroundcolor",{[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_1_},{[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_2_})
Here is the error that i get.
caused by ClassCastException: Error trying to coerce ‘{[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_1_}’ to a number.
I’m guessing that the script is waiting to receive a number as a parameter but i would like to send tags as a parameter.
Here is my script (it’s is only a test)
Please note that if I replace the parameter in the script TagsDB and TagsPLC and running the script without using runScript it is working . Thanks
def backgroundcolor(TagsDB,tagsPLC):
endTime = system.date.now()
startTime = system.date.now()
dataset=system.tag.queryTagHistory(paths=['TagsDB'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Maximum", returnFormat='Wide')
print dataset.getValueAt(0,1)
tagsr=(["tagsPLC"])
valuer=system.tag.readAll(tagsr)
print valuer[0].value
if valuer[0].value != dataset.getValueAt(0,1):
print 'different'
Your first problem is that you’re skipping a required argument for the runScript
function - if you’re passing any arguments, you must also pass a rate. If it’s an expression tag, leave the rate 0 so that the script evaluates at the scan class execution rate:
runScript("shared.backgroundcolor.backgroundcolor", 0, {[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_1_},{[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_2_})
Your second problem is that what you’re trying to do doesn’t really make sense. You’re passing in the values of tags to a function that then tries to use those as tagpaths. In expressions, the curly brace around a tagpath ({[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_2_}
) means evaluate and return the value of this tag. But, your defined function is (attempting to) act like it’s getting tag paths, which it’s not. If you do actually want to pass tagpaths to your script, then drop the curly braces:
runScript("shared.backgroundcolor.backgroundcolor", 0, "[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_1_", "[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_2_")
Finally, your script is not interpeting the tagpaths correctly; you’re not using the parameters passed into the script at all:
def backgroundcolor(TagsDB, tagsPLC):
means that when your script executes, it will have access to two local variables: TagsDB
and tagsPLC
. With the modified runScript
expression posted above, those will now be literal strings. However, in your code you’re doing things like:
dataset=system.tag.queryTagHistory(paths=['TagsDB']
'TagsDB'
is another literal string at this point - it has no relation whatsoever to the TagsDB
variable that already exists. Drop the quotes around the parameters, because they’re completely defeating the purpose of what you’re trying to do. Also, if you’re running this from anything “gateway” scoped (ie, an expression tag) the print
statements are only going to show up in the wrapper.log
file - nowhere else.
Thanks for your help and quick answer great service provided by all of you guys!
I new to scripting and didn’t know all this !
It’s all working now !!
1 Like