System.tag.write not writing all tags

I’m trying to write 14 tags with a script in a button actionperformed event:

root = system.gui.getParentWindow(event).rootContainer

preset1 = root.getComponent('1L').intValue
tag1 = str(root.Dados.Meta.TagPath+"/something")
...
preset14...
tag14...
preset_values = ([preset1],...[preset14])
tag_paths = ([tag1],,...[tag14])
system.tag.writeAsync(tag_paths,preset_values)

but only the last two tags are being sent to my PLC. These tags are referenced to a custom property of a UDTProperty type in my screen, that points to UDT Tag with derived type and the source tag path is like

[MQTT Engine]Edge Nodes/{AreaName}/{TAG}/PI0{Index}/PropertyN_{TAG}

I’m using Cirrus Link MQTT Engine module to my PLC.

If I try to write one by one of the 14 tags and put a sleep() in between system.tag.writeAsync(tag_paths,preset_values) 14 calls, it works, but I know that sleep() is not welcome. How can I get my 14 tags successfully written?

any help would be greatly appreciated.

You've created tuples of single-element lists with this construct.

Should be like:

preset_values = [preset1,...preset14]
tag_paths = [tag1,,...tag14]
1 Like

As an aside...

Bad

root = system.gui.getParentWindow(event).rootContainer

preset1 = root.getComponent('1L').intValue
tag1 = str(root.Dados.Meta.TagPath+"/something")
...
preset14...
tag14...

preset_values = [preset1,...preset14]
tag_paths = [tag1,...tag14]
system.tag.writeAsync(tag_paths,preset_values)

Better

root = system.gui.getParentWindow(event).rootContainer

values = []
tags = []

values.append(root.getComponent('1L').intValue)
tags.append(str(root.Dados.Meta.TagPath+"/something"))
...

system.tag.writeAsync(tags, values)

Best

root = system.gui.getParentWindow(event).rootContainer

tags = [
	str(root.Dados.Meta.TagPath+"/something"),
	...
]
values = [
	root.getComponent('1L').intValue,
	...
]

system.tag.writeAsync(tags, values)

Writing out a bunch of abc1, abc2, abc3 variables is pointless - at best it invites typos.

3 Likes

Thank you for pointing that, I fixed this one!

I modified my code to match this example, but it’s still not working properly. Some tags are written and some are not. I’m starting to think it might be related to some gateway read/write configuration.

Provide a callback to receive the write status codes, and log them.

@pturmel

I received a positive feedback from callBack, but most of my values ​​were not sent to the PLC.

Script console

Output console

If I click countless times Execute in Script console, eventually some values are sent, but not all of them. Same with my button at runtime.

system.tag.write is not writing directly to the device. It is writing to the Ignition Tag. Depending on the type of tag that is, how it is configured, and how the device is configured, values may take longer than you’re expecting to be written to the PLC. Note that it is also possible that the device itself is over writing your values and so they are being sent but the PLC is wiping them out.

1 Like

I have to point out that your code does not match the example.

In your screenshot, line 20 is not a list. In Paul’s example, it is definitely a list, so line 20 should be:

values = [1,2,3,4,5,6,7…]

Likewise, your tags variable is not a list aswell. It is a tuple.

So on line 6, your variable declaration should be:

tags = ['path1', 'path2', 'path3'…]

Please note the use of brackets instead of parenthesis.

Also, please do not specify .value in your list of paths. By default, a value is written to the value of a tag if nothing is specified in the path ( .documentation, .tooltip, etc…)

3 Likes

@Samuel_Sueur Sorry about that, I modified to test with script console…on my root container the code is as follows:

Button script

Post code, not pics of code. (You did so well in your OP but then fell on your face...)

Here it is:

def callBack(asyncReturn):
	if not all(case.good for case in asyncReturn):
		print "Error writeAsync quality codes:" + str(asyncReturn) + "."
	else:
		print "writeAsync ok"
root = system.gui.getParentWindow(event).rootContainer
tags = [
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_1L"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_2L"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_3L"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_4L"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_5L"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_6L"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_7L"),
	
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_1H"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_2H"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_3H"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_4H"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_5H"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_6H"),
	str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_7H")
		]
values = [
	root.getComponent('1L').intValue,
	root.getComponent('2L').intValue,
	root.getComponent('3L').intValue,
	root.getComponent('4L').intValue,
	root.getComponent('5L').intValue,
	root.getComponent('6L').intValue,
	root.getComponent('7L').intValue,
	
	root.getComponent('1H').intValue,
	root.getComponent('2H').intValue,
	root.getComponent('3H').intValue,
	root.getComponent('4H').intValue,
	root.getComponent('5H').intValue,
	root.getComponent('6H').intValue,
	root.getComponent('7H').intValue
		]

system.tag.writeAsync(tags, values, callBack)

I don't see anything obviously wrong. It may not be a script issue.

1 Like

You might have it print/log the tag paths and values to make sure you're getting what you expect.

1 Like

I ended up writing this code, using this method all my values are sent to the PLC via MQTT, but unfortunately I couldn’t get rid of the sleep() function:

system.tag.writeBlocking(["[default]Animation/HabWait"], True)
root = system.gui.getParentWindow(event).rootContainer
tag_writes = [
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_1L"), "value": root.getComponent('1L').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_2L"), "value": root.getComponent('2L').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_3L"), "value": root.getComponent('3L').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_4L"), "value": root.getComponent('4L').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_5L"), "value": root.getComponent('5L').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_6L"), "value": root.getComponent('6L').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_7L"), "value": root.getComponent('7L').intValue},	
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_1H"), "value": root.getComponent('1H').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_2H"), "value": root.getComponent('2H').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_3H"), "value": root.getComponent('3H').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_4H"), "value": root.getComponent('4H').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_5H"), "value": root.getComponent('5H').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_6H"), "value": root.getComponent('6H').intValue},
	{"path": str(root.Dados.Meta.TagPath+"/PRESET_LIMITES/LIMITE_7H"), "value": root.getComponent('7H').intValue}
		]
for i in range(1): # Iterates from 0 to 1
        if(system.gui.confirm("Write values?", "Confirm")):
			if(event.source.parent.getComponent('HabWait').visible):
				for item in tag_writes:
					from time import sleep
					values=item["value"]
					paths=item["path"]
					def write (values=values):
						system.tag.writeAsync(paths, values)
					system.util.invokeAsynchronous(write) # Pause execution for the specified delay
					sleep(1) #delay
			system.gui.messageBox("Updated", "Ok!")
system.tag.writeBlocking(["[default]Animation/HabWait"], False)

Thank you for your support!