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
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?
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.
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.
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…)
I ended up writing this code, using this method all my valuesare 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)