I'm trying to use a gateway tag change script to get a value change in a tank (with corresponding start and end times) so I can get flow in to the tank from two historicised flow meters (using tagHistoryQuery), and calculate outflow (there isn't a meter on the outflow because Reasons).
The tank and inflow tags are OPC.
The outflow I'm trying to write to is a memory tag set to 'float'.
Script that is Just Not Working At All:
if not initialChange:
damTot = "[default]OPCTag1"
ufTot = "[default]OPCTag2"
paths = [damTot,ufTot]
oldLvl = previousValue.getValue()
newLvl = newValue.getValue()
startT = previousValue.getTimestamp()
endT = newValue.getTimestamp()
inData = system.tag.queryTagCalculations(paths, "Range", startT, EndT)
inFlow = inData.getValueAt(0,1)+inData.getValueAt(1,1)
outFlow = oldLvl+inFlow-newLvl
system.tag.writeBlocking(["[default]MemoryTag"], outFlow)
I've tried using event.getCurrentValue().getValue() and event.getPreviousValue().getValue() instead of previousValue.getValue() and newValue.getValue();
I've tried previousValue().getValue() and newValue().getValue();
I've tried calling a project script:
if not initialChange:
oldLvl = previousValue.getValue()
newLvl = newValue.getValue()
startT = previousValue.getTimestamp()
endT = newValue.getTimestamp()
payload = {"oldLvl":oldLvl, "newLvl":newLvl, "startT":startT, "endT":endT}
outFlow = runTest.cwtOut(oldLvl, newLvl, startT, endT)
with the path allocation, tag calcs and writeBlocking in the project script.
But it just seems to not work at all.
All I get in the gateway log is "Error executing tag change script: Project/ScriptName"
I am at a loss what to do to fix it...
help please?