Skip to main content
Version: 8.1

Reading and Writing to Tags

In many cases, the binding system is the most appropriate way to display a Tag value on the screen. However, you may wish to access a Tag's value in a script. Using the system functions, you can read from a Tag and write to a Tag in Ignition.

Inductive University

Reading and Writing Tags

Watch the video

Script Builder​

If you simply need to write to value to a Tag from a script, you can use the Set Tag Value tab of the Script Editor. To learn more, refer to the sections on Script Builders for more information. However, if you need to do more than just send a single write, see the section below.

Know Your Scope​

Whenever a script from a Shared resource (such an Alarm Pipeline) attempts to interact with a Tag, the script must specify the Tag Provider, otherwise, the script could return an exception. Tag Providers are always included at the start of the Tag Path and look like the following: [tagProvider]

When interacting with a Tag from the Project scope (such as a script on a component) you may optionally include the Tag provider. If omitted, the Project default Tag provider will be used.

Pseudocode - Tag Read Scope
# Reading a Tag without the Tag Provider. You would not want to use this from the Shared scope.
system.tag.readBlocking(["My/Tag/Path"])

# Reading from the same Tag, but specifying the Tag Provider. This format may be used safely in either scope.
system.tag.readBlocking(["[default]My/Tag/Path"])

Manual Tag Reads​

Reading from a Single Tag​

Reading a Tag from a script is accomplished with the system.tag.readBlocking() function, which requires the Tag path you wish to read from. This function returns a 'Qualified Value'; this object is more than just the value. A Qualified Value is the Tag value that has three attributes; Value, Quality, and TimeStamp.

The function normally expects a list of Tag paths, but can be used with a single Tag: simply provide a list of only a single Tag path.

When handling the results of the read, the results will be returned in a list of qualified values, so you'll need to specify which qualified value you're interested in via Python slicing, even if there is only a single qualified value in the list.

Pseudocode - Reading Tag Attributes
# get the Tag value
value = system.tag.readBlocking(["tagPath"])[0].value

# get all three attributes
tag = system.tag.readBlocking(["tagPath"])[0]
value = tag.value
quality = tag.quality
timestamp= tag.timestamp

Reading from Multiple Tags​

The system.tag.readBlocking() function can easily be used to read multiple Tags in a single call:

Python - Reading Multiple Tags and Printing the Values
# Create a List of Tag Paths to read
paths = ["Scripting/Tags/Alarm_1", "Scripting/Tags/Alarm_2", "Scripting/Tags/Alarm_3"]

# Read the Tags, and store the complex results in a variable
values = system.tag.readBlocking(paths)

# For each Tag Path, iterate through our results...
for index in range(len(paths)):

# ...and do something with the individual values
print values[index].value

Relative Tag Paths​

Like elsewhere in Ignition, relative paths may be used from within a script. This is especially useful when writing a Tag Event script inside of a UDT, as you can specify relative members in the same UDT with "[.]".

Pseudocode - Reading with Relative Tag Paths
# Assuming a UDT with two sub-members, a script from one can read from one member to the other using the following code:
system.tag.readBlocking(["[.]otherMember"]).value

Manual Tag Writes​

Writing to a Single Tag​

Much like reading, there is a function you can use to write to Tags: system.tag.writeBlocking. It requires a list of Tag paths, as well as a list of values to write to those Tags.

Pseudocode - Tag Write
system.tag.writeBlocking(["tagPath"],["Hello World"])

Writing to Multiple Tags​

The system.tag.writeBlocking function can also write to multiple Tags, again by providing multiple paths and values.

Python - Multiple Tag Writes
# Create a List of Tag Paths to write to
paths = ["Scripting/Tags/Alarm_Setpoint_1", "Scripting/Tags/Alarm_Setpoint_2"]

# Create a List of values to write
values = [72, 72]

# Send of the write requests
system.tag.writeBlocking(paths, values)