Derived Tag Incrementing Memory Tag Value

system.tag.readBlocking(tagPaths, [timeout])

The documentation said to put the timeout inside the parenthesis. So I am confused why it works.

temp = system.tag.readBlocking(["[.]New Tag"])[0]
tempvariable = temp.value + 1
system.tag.writeBlocking(["[.]New Tag","[.]New Tag2"],[tempvariable,6])

Did work for me. Thank you very much.

I think you’re getting a little confused by all of the different contextual meanings of the ‘[ ]’.

In the documentation the brackets around a parameter mean that parameter is optional. If you opt not to provide a timeout then it defaults to 45000 milliseconds.

Now for the messy explenation:

In the code there are three different contextual meanings of ‘[]’.

  1. [] is the python specifier for a List
  2. [] is the python index operator
  3. [] in a tag path denotes the provider that should be used.

The first line actually uses all three of these.

Don’t feel bad it can certainly be daunting to someone who isn’t used to reading code. Those of us used to reading it can forget how cyrptic it can sometimes be.

Here is a slightly more verbose way to write the first line which I hope will help

#create a variable of type list with 1 element
#that element is a string representing a realtive tag path to
#the path of the tag where you are using this code
paths = ['[.]New Tag']

#creates a variable of type list whith the same number of
#elements in path.  Each element will be of type QualifiedValue
#notice that since the paths variable is already a list you do not surround it
#with '[]'. The default timeout will be used.
tagValues = system.tag.readBlocking(paths)

#create a variable equal to the value of the 0th element of the tagValues list
temp = tagValues[0].value

All of that can be done on one line, since were doing it on one line we don’t need to create variables to hold the values for use later.

temp = system.tag.readBlocking(['[.]New Tag'])[0].value

Thanks very much

I was definitely not used to the [] abundance in this language.

Ignition 8.1. I built a Gateway Timer script to make an error count each time an OPC hearbeat tag doesn’t update. The script did not work, so in debugging I stripped the script down to simply incrementing the tag each time the script runs. The tag does not increment. I looked at the logs, and found a JythonExecException Traceback; “unsupported operand type(s) for +: ‘java.util.ArrayList’ and ‘int’”. Casting to int makes it an unsupported operand type between a ‘com.inductiveautomation.ignition.common.model.values.BasicQualifiedValue’ and an int. Read / write blocking does not work either. What am I doing wrong? The tag is an integer and is a memory tag.

The script:
"
inputVal = system.tag.readBlocking("[default]intHeartbeat_Error_Count")
new = inputVal + 1
system.tag.writeBlocking("[default]intHeartbeat_Error_Count",new)
"

The log:
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File “”, line 2, in TypeError: unsupported operand type(s) for +: ‘java.util.ArrayList’ and ‘int’

at org.python.core.Py.TypeError(Py.java:265)

at org.python.core.PyObject._basic_add(PyObject.java:2159)

at org.python.core.PyObject._add(PyObject.java:2137)

at org.python.pycode._pyx155.f$0(:3)

at org.python.pycode._pyx155.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:171)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1614)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:796)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:678)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:744)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:659)

at com.inductiveautomation.ignition.common.script.TimerScriptTask.run(TimerScriptTask.java:92)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.runAndReset(Unknown Source)

at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: Traceback (most recent call last): File “”, line 2, in TypeError: unsupported operand type(s) for +: ‘java.util.ArrayList’ and ‘int’

… 19 common frames omitted

Okay you have a few mistakes in your script that are causing you the headache.

You will see if you look at the documentation for readBlocking and writeBlocking as posted by @Kevin.Herron:

That readBlocking and writeBlocking both take lists as arguments, and readBlocking returns a list of qualifiedValues.

Your script should look like this:

inputVal = system.tag.readBlocking(["[default]intHeartbeat_Error_Count"])[0].value
new = inputVal + 1
system.tag.writeBlocking(["[default]intHeartbeat_Error_Count"],[new])

Also if you surround your script and error logs with three back ticks ``` or click the preformatted text button </> it makes them much easier to read.

Ah, I see the error of my ways. Thank you!