def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
"""
Fired whenever the current value changes in value or quality.
Arguments:
tag: The source tag object. A read-only wrapper for obtaining tag
properties.
tagPath: The full path to the tag (String)
previousValue: The previous value. This is a "qualified value", so it
has value, quality, and timestamp properties.
currentValue: The current value. This is a "qualified value", so it has
value, quality, and timestamp properties.
initialChange: A boolean flag indicating whether this event is due to
the first execution or initial subscription.
missedEvents: A flag indicating that some events have been skipped due
to event overflow.
"""
print "currentValue", currentValue.value
window = system.gui.getWindow("OPCUA Monitor 1 Root")
dataset = window.getComponentForPath("Root Container.MessageLog").data
#dataset = event.source.getComponent("MessageLog").data
pdataset = system.dataset.toPyDataSet(dataset)
pdataset.addRow([currentValue])
dataset = system.dataset.toDataSet(pdataset)
window.getComponentForPath("Root Container.MessageLog").data = dataset
#event.source.getComponent("MessageLog").data = dataset
Even though system.gui autocompletes it is telling me that “gui” does not exist.
Error executing script.
Traceback (most recent call last):
File "<tagevent:valueChanged>", line 4, in valueChanged
AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'gui'
You are right. I needed to bind a memory dataset tag to my List. Now I am trying to update the memory dataset by adding rows. Each time the value changes I need to add a row. So it acts like a message log:
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
"""
Fired whenever the current value changes in value or quality.
Arguments:
tag: The source tag object. A read-only wrapper for obtaining tag
properties.
tagPath: The full path to the tag (String)
previousValue: The previous value. This is a "qualified value", so it
has value, quality, and timestamp properties.
currentValue: The current value. This is a "qualified value", so it has
value, quality, and timestamp properties.
initialChange: A boolean flag indicating whether this event is due to
the first execution or initial subscription.
missedEvents: A flag indicating that some events have been skipped due
to event overflow.
"""
tlist = ["MessageLogDataset"]
tags = system.tag.readBlocking(tlist)
print tags
print currentValue.value
for tag in tags:
dataset = tag.value
break
system.dataset.addRow(dataset,0,[currentValue.value])
system.tag.writeBlocking(tlist, [dataset])
I don’t get any errors, it does not update the dataset tag (even though the tag initiating this event does update), I never see the print values. The only time I see info is when it tells me there is an issue with the script in the tag properties window. How do i get tag scope print messages to show in the console?
Kind of out on a limb here, but perhaps the fact that “tag” is used as a parameter in the function definition and you use it as the loop variable, things aren’t working as expected?
All of the dataset manipulation functions return a new dataset; they don’t modify the existing one. You need to write the new dataset value you get from calling this function.