There is likely a simple solution to this issue, but I just can't think of the right way to do this.
I'm trying to write UDT parameter value to an OPC tag value if the tag value is not equal to parameter value. In this case, you can see in the attached image, I have multiple identical UDTs, with the instances named 701 - 730. I'd like to write the "ID" Parameter value, "703" to the value of the OPC tag "MachineNumber". What's the simplest way of doing this?
That would probably work too. Here is what I came up with, I used a gateway script on tag change which watches the MachineNr Tags for value change. If a value changes, this script is executed:
# Loop through the UDT instances
for i in range(703, 730):
# Construct the UDT and OPC tag paths
paramName = "Id"
udtInstancePath = "[default]Continuity/{}_1".format(i) # Use format method here
paramPath = "{}/Parameters.{}".format(udtInstancePath, paramName)
opcPath = "[default]Continuity/{}_1/MachineNumber".format(i) # Use format method here
# Get the values
idParamValue = system.tag.read(paramPath).value
machineNumberTagValue = system.tag.read(opcPath).value
#print(idParamValue)
#print(machineNumberTagValue)
# Write the parameter value to the OPC tag if they differ
if machineNumberTagValue != idParamValue:
system.tag.write(opcPath, idParamValue)
The reason this is needed is because we have 30 identical machines. When we make changes to one of them, we download the same program to all of them. The only thing different in each program is the machine number tag value.
Personally, this would be the easiest in my opinion. Just put a Value Changed script on the MachineNumber tag inside your UDT with this script (indent appropriately):