Gateway Tag Change Script help (probably syntax)

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?

There should be more error info on the gateway, did you expand the error message? Next, I would add a logger to see if the values are what you expect.

logger = system.util.getLogger('inflowScript')
logger.info(str(oldLvl))
...

These messages will show up in the gateway logs. Another thing to try is to change your tag calculation to this.

inData = system.tag.queryTagCalculations(paths, ["Range"], startDate=startT, endDate=EndT)
1 Like

@dkhayes117
There is not more error info on the gateway as far as I can tell. That's the whole error message, and there isn't a little "+" to click on or anything.

I'll try the tag calculation you suggest :slight_smile:
Thanks

1 Like