Modify UDT member tag with system.tag.configure

Hi

I want to modify the members of UDT tag with system.tag.configure. For example OpcItemPath.
Can someone help me on that.
The old system.tag.write(tagFolder + tag + ‘.OPCItemPath’,OPCItemPath) doesn’t work anymore.

Thanks.

1 Like

this is for changing parameters within a UDT, but it should be the same:

def updateParameterValue(path,paramName,newValue):
	import system
	# Get current configurations
	tagPath=str(path)
	print tagPath
	tags = system.tag.getConfiguration(tagPath)
	empty=[]
	for tagDict in tags:
		# Iterate over the dictionary with the iteritems function
		for key, value in tagDict.iteritems():
			# Do something with the keys and values
			#print key, ' : ', value
			empty=[]
	tag1=tags[0]
	tag1['parameters'][paramName]=newValue
	tagList=[tag1]
	
	collisionPolicy = "o"
	baseTagPath=tagPath.rsplit("/",1)[0]
	print "Writing data to: %s, Parameter: %s, New value : %s" % (path,paramName, newValue)
	system.tag.configure(baseTagPath, tagList, collisionPolicy)
	print "Tag updated!"
2 Likes

Thanks but is there any easier way to access opcItemPath?
I dont get the members.
When I try to access member with system.tag.configure i get invalid tagpath error.
So I wonder how change member attribute with system.tag.configure().

tagName = "PI05051/PV"
opcItemPath = "ns=1;s=[Simulator]_Meta:Sine/Sine0"
opcServer = "Ignition OPC-UA Server"
valueSource = "opc"
 
# Configure the tag.
tag = {
            "name": tagName,           
            "opcItemPath" : opcItemPath,
            "opcServer": opcServer,
            "valueSource": valueSource,
        }
 
# Create the tag.
print system.tag.configure('DPB', [tag], 'm')

Dont know of any easier way, but i just tried this, and it worked:

def updateOPCPath(path,newOpcPath):
	import system
	# Get current configurations
	tagPath=str(path)
	tags = system.tag.getConfiguration(tagPath)
	empty=[]
	for tagDict in tags:
		# Iterate over the dictionary with the iteritems function
		for key, value in tagDict.iteritems():
			# Do something with the keys and values
			#print key, ' : ', value
			empty=[]
	tag1=tags[0]
	
	tag1['opcItemPath']=newOpcPath
	tagList=[tag1]
	
	collisionPolicy = "o"
	baseTagPath=tagPath.rsplit("/",1)[0]
	system.tag.configure(baseTagPath, tagList, collisionPolicy)
	print "Tag updated!"
updateOPCPath(tagpath,newOpcPath)
tagpath="[Remote_Ignition_DataServer]temp/myOPCTag"
newOpcPath="ns=1;s=[Simulated_Device]_Meta:Ramp/Ramp2"
1 Like

Ok my problem is if you have a UDT with several folder in it, the tag1['opcItemPath']=newOpcPath doesn’t go to the deepest level I want.

Area1/PI053401/ALARM/Setpoint/HighSetpoint
Area1 = folder
PI053401 = UDT instance = main tag
/ALARM/Setpoint/ = folder structure in UDT
HighSetpoint = Atomic Tag in UDT

So how I can go to HighSetpoint.opcItemPath?
Your code only access to first level opcItemPath, if the tag is normal and NOT UDT.

I think i understand.

This one works for members of UDT’s. It is a bit crude/hard coded, and you need to find the index of the tag within that UDT. But it might get you started.

The main issue i get here, is that all tags within the UDT get overwritten. Even though i dont change them. Maybe you will find out why…

image


import system
path="[Remote_Ignition_DataServer]temp/UDT1"
baseTagPath="[Remote_Ignition_DataServer]temp"

# Get current configurations
tagList = system.tag.getConfiguration(tagPath,True)
tagDict=tagList[0]


tagDict["tags"][0]["opcItemPath"]=u"ns=1;s=[Simulated_Device]_Meta:Ramp/Ramp2"
tagDict["tags"][1]["opcItemPath"]=u"ns=1;s=[Simulated_Device]_Meta:Ramp/Ramp3"
tagListNew=[tagDict]

collisionPolicy = "m"

print baseTagPath
system.tag.configure(baseTagPath, tagListNew, collisionPolicy)
print "Tag updated!"

Thanks. but I in your code you assume that you know the UDT structure. If you have a dynamic path how do you create the structure?
Imagine this
Path = Area1/CompB/…/SectionB/Temp/PV
in this example you don’t know how many deep level you have and is each level is folder or another UDT.
in v7.9 I simply pass Path to system.tag.write like this:
system.tag.write(Path + “.opcItemPath”, “ns=1;s=[Simulated_Device]_Meta:Ramp/Ramp2”)
but in v8 it doesn’t work.
Do you know any workaround for this?

The solution I gave in the other post is more complex to deal with the request to build the structure for any nesting level from the same base path. Here’s a simple direct system.tag.configure replacement for the tag write to tag property that you have above:

def overrideTagProperty(path, value):
	basePath, name, overrideProperty = path.replace('.','/').rsplit('/', 2)
	system.tag.configure(basePath, [{'name':name, overrideProperty:value}], 'm')

overrideTagProperty(Path + ".opcItemPath", "ns=1;s=[Simulated_Device]_Meta:Ramp/Ramp2")
4 Likes

I had the same problem @nader.chinichian. Just replace the system.tag.write(tag, value) function to system.tag.writeAsync([tag], [value]).

It doesn’t work if the property inherent from udt parent. Because if see json of the tag that property doesn’t include and so system.tag.writeasync doesn’t work.