Hello, I am new to ignition, and I was wondering if there was a way to aggregate the value of a tag within another tag using scripting such as in an expression tag. (Without using tag history)
Possible... but can you give more information about what you are trying to do?
I'm trying to aggregate the total flow that passes through a flow meter. Essentially, the total flow tag will take the value of the flowmeter tag every minute and add it to itself to give the total flow over a period of time.
Sure. You could use a gateway timer script for that. It might get tricky with an expression tag.
I would have one tag that would be the live flow value, and then another that is your totalized value. Ready the live flow and the totalized values with system.tag.readBlocking, do the math and then write to the totalized with system.tag.writeBlocking.
IE (Not tested or optimized etc... )
liveTagPath = 'somePath' totalTagPath = 'anotherPath' values = system.tag.readBlocking([liveTagPath,totalTagPath]) system.tag.writeBlocking([totalTagPath], [values.value + values.value])
As @Transistor notes below this isn't the best way to do this in real life to try and get accurate values.
The normal approach to this is to use the tag historian to log the flowmeter value every minute. Then you write a tag history query to sum the values over the period of interest, say
now()- 1 hour to
now(). This is effectively inegrating the flowmeter output with respect to time to give you the flow for that period.
Do note that this only gives you an average based on the snapshot readings. If your meter readings fluctuate between samples you'll have errors. A better way is to use a pulse meter, have the PLC count pulses in a never-resetting counter and capture these in tag history. Then you can find the actual volume passed in any period and from that calculate averages, etc. (This would be more like how your electricity or water meter works and is read by the utility company - although maybe only once a month.)
I tried but it didn't work. Is there any optimization to the code I can try?
Any errors in the gateway status?
You can run that directly in the script console... any errors that show up would be helpful.
Yeah I understand it isn't the best solution to the problem but I was wondering if there was a way that it can work
Hey I tried it over and it worked! Thank you!!
Try my (free) Simulation Aids module's recorder() expression function. Use a dataset expression tag set to event driven execution.
Hello, I am also new to ignition, is there a way to get this to work with UDTs. I tried using UDT paths instead of Tag paths but the script did not work. Any help would be greatly appreciated.