I have two modbus-tcp devices configured and I have also built their respective OPC tags to detect the connection status to read in the gateway tag change script. The intention of the gateway tag change script is to change a bulk of tag's 'opcitempath' based on the healthy connection status of one of the active modbus device. The gateway script will write value "1" or "2" (which is suffix of the two modbus devices) to the UDT definition called "Redundant" with a string data type parameter called 'ActDev'.
I prepared script is running without any error, but it isn't changing the UDT parameter ActDev value as intended.
The gateway script is posted below, can anyone identify if anything is missing? thanks in advance.
def changeUDTParameter():
UDT definition path
udtDefinitionPath = TagPath.parse('[default]_types_/Redundant')
UDT parameter name
udtParameterName = 'ActDev'
Read the current value of the connection status tag
connectionTagPath1 = system.tag.readBlocking("[System]Gateway/Devices/Tri_11_2_Dev1/Status")[0].getValue()
connectionTagPath2 = system.tag.readBlocking("[System]Gateway/Devices/Tri_11_2_Dev2/Status")[0].getValue()
Set the new value for the UDT parameter based on the connection status
if ("Connected" not in connectionTagPath1):
if ("Connected" in connectionTagPath2):
# Update the UDT definition parameter with the new value
system.tag.writeBlocking([udtDefinitionPath], {udtParameterName: 2})
else:
system.tag.writeBlocking([udtDefinitionPath], {udtParameterName: 1})