Writing to tag values on a gateway timer script (Ignition v7.9.6)

Hello,

I am attempting to write to a tag that runs on a gateway timer script. Essentially we are reading a value from a flowmeter and are attempting to obtain the flow from this meter for the entire month by adding it continually. I’m sure this is just a syntax issue but we can’t seem to get this to work. Any pointers would be appreciated, thanks!

you need to READ the tags for the values in scripting.

sum2 = system.tag.read('[default[PathToFlowTag').value + system.tag.read('[default[PathToSumTag').value
system.tag.write('[default]PathToSumTag',sum2)

Definitely a step in the right direction, I appreciate your response. The script still doesn’t seem to be working however, CURR_MONTH_FLOW_TOT is still 0, so it’s not being written to. Sidenote: Are you sure that the “.value” in system.tag.read is written outside of the parenthesis, and not inside of it? I tried it both ways and it didn’t work either way, but I’m honestly just curious. I’m not really sure where to go from here, but I’m attaching a screenshot of the new script. Thanks!

Reading a tag gives a ‘qualified value’ with three components, value being one of them.

Howerver, Curr_Month_Flow does not need .value when you write to a tag.

Getting closer it seems, but still not quite there. Scripting in Ignition is definitely my weak point so I appreciate the assistance. I wonder if maybe it isn’t working because Curr_Month_Flow is a summation of two system.tag.read functions?

You removed the .value from your reads, it needs to be there. Try:

Curr_Month_Flow = system.tag.read("[Gretna]Analog/CURR_MONTH_FLOW_TOT").value + system.tag.read("[Gretna]Analog/FIT_501/PV").value
system.tag.write("[Gretna]Analog/CURR_MONTH_FLOW_TOT",Curr_Month_Flow)

I had tried it earlier and it wasn’t working. So I removed them just to experiment, just forgot to put the “.value” back. I just tried exactly what bpreston suggested and still no dice. Maybe it’s possible that the problem at this point doesn’t lie in my syntax? I checked the gateway logs and no errors are showing up, but I see the same thing posted all over the log. Attaching screenshot, thanks everyone.

I doubt the screenshot has much to do with my current issue. It doesn’t seem as though the timer script is even running though.

Yea it seems like the script doesn’t like the “+” in my script. I found out how to check the script error on the gateway and found this:

Traceback (most recent call last):
File “<TimerScript:IMTT_Gretna_2015/Current_Total @5,000ms >”, line 1, in
TypeError: unsupported operand type(s) for +: ‘com.inductiveautomation.ignition.common.sqltags.BasicTagValue’ and ‘com.inductiveautomation.ignition.common.sqltags.BasicTagValue’

7.9.6 (b2018012914)
Oracle Corporation 1.8.0_161

Try testing it in your script console instead of the timer script.

Try:

mft = system.tag.read("[Gretna]Analog/CURR_MONTH_FLOW_TOT").value
fit = system.tag.read("[Gretna]Analog/FIT_501/PV").value
print "MFT:",mft
print "FIT:",fit

Curr_Month_Flow = mft + fit
print Curr_Month_Flow

What does it print if you do this or do you get an error?

1 Like

It worked fine in the console, so I somewhat replicated what you just suggested and we finally got it working. Thanks a lot for your help!