writeBlocking to a Memory Tag works in Script Console but not in Gateway Timer Event Script

Hello all - very new to Ignition scripting.

I am simply trying to copy the value of one memory tag to a different memory tag. This code works in the scripting console. I am able to write to a memory tag "P1UptimeBit" based on the tag "SPOOF Press 1 Line Speed". However, as soon as I copy it over to a Gateway Timer Event Script specified to fire every second, the tag no longer updates. Code below...

writevalue = system.tag.readBlocking(["[default]TEST/SPOOF Press 1 Line Speed"])
system.tag.writeBlocking(["[default]TEST/P1UptimeBit"], writevalue)

Rather surprised it worked in the Console. Reading a tag gets a "qualified value" with three parts: value, quality, and timestamp.

You want to grab the value portion of it and writ it to another tag.

Try this:

writevalue = system.tag.readBlocking(["[default]TEST/SPOOF Press 1 Line Speed"])[0].value
system.tag.writeBlocking(["[default]TEST/P1UptimeBit"], [writevalue])

To clarify further,:

["[default]TEST/SPOOF Press 1 Line Speed"]

is a list of tags, even if it's a list of one. The [0] after it says the you want to get the qualified value at position 0. Things that you can iterate over start at an index of 0.

The .value at the end gets the value portion of the qualified value.

1 Like

Hey Jordan - thanks for the quick reply. I copied that directly into the Gateway Event Script and still no luck. Your code runs in the Script Console as well... Dumb question - how do I get my code to show up formatted in the forum?

Welcome to the forum, Eric. Please have a read of Wiki - how to post code on this forum. It might save us some confusion.
.

On the writing of tags, you again have a list of tags, thich also requires a list of values. That's why there are brackets around both.

Got it - and updated my original post. Thanks guys.

1 Like
  • Did you remember to save the project?
  • Is there any error in the logs?
1 Like

It seems all I needed to do here was save the project - as silly as it feels to admit. Thanks Jordan.

IIRC under the hood it knows how to handle qualified values.

1 Like

More than that, it's deliberate that you're allowed to pass qualified values through, in case you want to write an explicit quality code and/or timestamp to, say, a memory tag.

3 Likes

So did I inadvertently pass all of those parameters (quality, timestamp, value) to the memory tag - is that possible? ...or does Ignition make an assumption if a parameter is not specified?

You did. readBlocking() returns a list of QualifiedValues, in a 1:1 relationship with the paths passed in the list of TagPaths. writeBlocking() accepts a list of objects in a 1:1 relationship with the paths passed in the list of TagPaths. Those objects can be QualifiedValue objects.

If you wanted just the value attribute of the QualifiedValue then you would use code as @JordanCClark showed.

1 Like