Optimizing several tag writes

Hi,

I have a recipe screen that the operator can pick a part number for and enter in a work order. Once they do that they hit the load button and I take the info from a dataset and write it to the PLC. I wanted to ask you guys what the most efficient way to write the data to the tags is as we will be doing this process repeatedly. I have attached the working code I have now. I have looked into some of the different tag.write methods but was a little confused which one is best to use.

data = event.source.parent.HangerData

DryingRoom = data.getValueAt(0, "DryingRoom")
RobotNumber = data.getValueAt(0, "RobotNumber")
MaxDryTime = data.getValueAt(0, "MaxDryTime")
MinDryTime = data.getValueAt(0, "MinDryTime")
ManualPick = data.getValueAt(0, "ManualPick")

system.tag.write("SMS_HangerDataBuffer/CoatToProcess/DryTimeMax", MaxDryTime)
system.tag.write("SMS_HangerDataBuffer/CoatToProcess/DryTimeMin", MinDryTime)
system.tag.write("SMS_HangerDataBuffer/CoatToProcess/ManualStationRequired", ManualPick)
system.tag.write("SMS_HangerDataBuffer/CoatToProcess/RobotProgramNumber", RobotNumber)
system.tag.write("SMS_HangerDataBuffer/CoatToProcess/ShellCoatsDryRoom", DryingRoom)


system.nav.closeParentWindow(event)

Use system.tag.writeAll:

Performs an asynchronous bulk write. Takes two sequences that must have the same number of entries. The first is the list of tag paths to write to, and then second is a list of values to write. This function is dramatically more efficient than calling write multiple times.

data = event.source.parent.HangerData

# List tags.
tags = ["SMS_HangerDataBuffer/CoatToProcess/DryTimeMax"]
tags.append("SMS_HangerDataBuffer/CoatToProcess/DryTimeMin")
tags.append("SMS_HangerDataBuffer/CoatToProcess/ManualStationRequired")
tags.append("SMS_HangerDataBuffer/CoatToProcess/RobotProgramNumber")
tags.append("SMS_HangerDataBuffer/CoatToProcess/ShellCoatsDryRoom")

# List values.
values = [data.getValueAt(0, "MaxDryTime")]
values.append(data.getValueAt(0, "MinDryTime"))
values.append(data.getValueAt(0, "ManualPick"))
values.append(data.getValueAt(0, "RobotNumber"))
values.append(data.getValueAt(0, "DryingRoom"))

# Write all values to tags.
system.tag.writeAll(tags, values)
2 Likes

Thank you. is there a way to shorten the path part of the tag since they all have the same starting path?

tagRoot = "SMS_HangerDataBuffer/CoatToProcess/"
tags = [tagRoot + "DryTimeMax"]
tags.append(tagRoot + "DryTimeMin")
tags.append(tagRoot + "ManualStationRequired")
tags.append(tagRoot + "RobotProgramNumber")
tags.append(tagRoot + "ShellCoatsDryRoom") 
tagRoot = "SMS_HangerDataBuffer/CoatToProcess/"
tags = [tagRoot + x for x in ["DryTimeMax", "DryTimeMin", "ManualStationRequired", "RobotProgramNumber", "ShellCoatsDryRoom"]]
3 Likes

Although it doesn’t make much difference with a short list like this, you may find it advantageous to give the dataset columns names equal to the tag names . Then the list of tags and list of values may both be constructed from one list of names in a for loop.

1 Like