system.tag.writeBlocking sometimes doesn't update the Timestamp? with BasicQualifiedValue

So I have a (well actually I have dozens, but I've narrowed down the problem to just one) Integer memory tag (and some reference and expression tags pointing at it), and its value stays constant most of the time. I have a script running every 8 seconds to ask a server on the network for the latest value, and I use a block of code like this to update the tag:

TESTING_OFFSET = -1000

from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue

# Create a BasicQualifiedValue with value 100
bqv = BasicQualifiedValue(100)
bqv.timestamp = system.date.addYears(system.date.now(), TESTING_OFFSET )

# Write the BasicQualifiedValue to a Tag path
system.tag.writeBlocking(["[ThermotronDev]ThermatronDev/integer"], [bqv])

I use the timestamp in another script to confirm that the other script ran successfully within the past 8 seconds.

Here's a test I wrote to confirm that Ignition isn't saving my timestamp:

TESTING_OFFSET = -1000

from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue

# Create a BasicQualifiedValue with value 100
bqv = BasicQualifiedValue(100)
bqv.timestamp = system.date.addYears(system.date.now(), TESTING_OFFSET )
print("input timestamp: {}".format(bqv.timestamp))

# Write the BasicQualifiedValue to a Tag path
system.tag.writeBlocking(["[ThermotronDev]ThermatronDev/integer"], [bqv])

#confirm that the bqv's timestamp was saved in the Ignition Tag
tagsTimestamp = system.tag.readBlocking(["[ThermotronDev]ThermatronDev/integer"])[0].timestamp
print("output timestamp: {}".format(tagsTimestamp))
assert tagsTimestamp == bqv.timestamp, "the timestamp wasn't saved! :("
#if assertion succeeded:
print("the timestamp was saved! :)")

The assertion only succeeds if the value of the BasicQualifiedValue is changed from the number it was last time I ran this test script. If the value of the BasicQualifiedValue is the same, or if just a value is used instead of a BasicQualifiedValue (like True or False, and the value is the same as last time), then the assertion fails.

Should I try to work around this? e.g. by setting all of my tags' values to null for a few milliseconds before writing new values? Or maybe I'm using the timestamps feature wrong?

Timestamp-only changes won't propagate. You have to change the value.

They should if the deadband mode is off though.

https://docs.inductiveautomation.com/display/DOC81/Tag+Properties

The other thing that might be at play here is the "Allow back-fill data" advanced setting on Tag Providers.

That description of "Off" was written by somebody who was confused.

Deadband off means any value change, i.e. previous value != current value, with no regard for how small the change was in either absolute terms or as a percentage of engineering range.

I'm sure I've used this before though to change just timestamps. When you say current value!= previous value, are you meaning qualified values? Or the value properties of these?

The deadband actors only care about the quality and value component, they aren't looking at timestamp.

I don't think it's applicable because tag history is disabled for this tag provider?

Only mentioned it because you were creating timestamps in the past, and I think there are some quirks if you try update a tag value with a timestamp prior to the current one.

Setting the Deadband Mode to Off seems to fix the issue my test code, thanks! I will try to implement that in my main project.

I'm now wondering if all the stuff I'm saying is only applicable to OPC tags...

Allow Back-fill Data
If enabled, data will be allowed to arrive out of order from the source.
Data from the past will be stored to history, but will not be used for alarms, scripts, or subscriptions.
If false (default behavior), each value will be processed fully as it arrives.
(default: false)

It seems like my desired value for this setting is the same as default, false.

Yeah, I think you're right, and @nminchin too. Carry on.

2 Likes

I'm now wondering if all the stuff I'm saying is only applicable to OPC tags...

FWIW - It appears that writing to OPC tags will not take the qv's timestamp regardless of whether the value changes or whether the deadband is off.

As for the deadband, I had mixed experience with memory tags. Some worked only when the deadband was off (8.1.24), others also worked with absolute set (8.1.33). Neither gateway I tested with allowed backfill.