Change UDT Definition Parameter via SCADA Gateway Script

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})


Is the part that's setting the value the actual code that's running? Not sure if that syntax works for system.tag.writeBlocking(). When I reference parameters for reads, I'll put the parameter name in the path, like '[default]UDTInstance/Parameters/ActDev'. I would try using something like udtDefinitionPath + '/Parameters/ActDev' as the first argument and 1 or 2 as the second.

Also, how are you confirming that the code is executing? Might be worth it to create some test tag that you can do a simple write to. Write to it in the beginning to prove that the script is being called, then write something else in the end to prove that the script finishes.

The first parameter of the system.tag.writeBlocking() function takes a list of strings (one string representing the path of each tag you want to write to). So there is no need to try to parse the string into a tagPath.

udtDefinitionPath = ‘[default]_types_/Redundant’

As zbinder said, you can also include the parameter in your tagPath string.

udtParameterName = ‘ActDev’
tagPath = udtDefinitionPath + ‘/Parameters/‘ + udtParameterName
system.tag.writeBlocking([tagPath], [2])

https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking

2 Likes