Write OPC item path to custom property in UDT Instance

Hi,
I have UDT tags in different folders. I have created a custom property in UDT definition - called getOPCPath

i need to write a function to get the opc path of corresponding udt instance tag and write it to the custom property.

Why i am doing this because i am using MQQT so it's not fetching the OPC item path. so i am creating custom property and though that i am planing to fetch the OPC item path for all tags

this is the code i have used

parentPath = "[default]test_path"
 
# Get the current configurations recursivly, which is useful when targeting
#  folders and UDT Instances
configs = system.tag.getConfiguration(parentPath, True)
print configs
# The getConfiguration() above always returns a list of dictionaries, and our results
#  are inside of the first dictionary.
for tag in configs[0]['tags']:
 	print tag

it fetching all the udt tags in dictionary i don't know i how to Manipulate to each tag in dictionary and get their OPC item path and write it to same tag custom property

custom property i have created in each tag - GetOpcPath (its also there in dictionary )

[{u'tags': [{u'tags': [{u'tagGroup': u'2sec', u'tags': [{u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'expression': u'', u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWhTON, u'opcItemPath': u'OPC_Path3', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWhTON', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWhTON', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kW, u'opcItemPath': u'OPC_Path1', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'engHigh': 10.0, u'name': u'Consumption_kW', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kW', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWh, u'opcItemPath': u'OPC_Path2', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWh', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWh', u'valueSource': u'opc', u'historyMaxAge': 5}], u'path': Consumption, u'tagType': UdtInstance, u'name': u'Consumption', u'typeId': u'PFRCG12/Electric_v1', u'parameters': {u'OPC Server': {datatype=String, value=EMS PLC}, u'Database': {datatype=String, value=CHA_OT_Historian}}}], u'path': gas, u'tagType': Folder, u'name': u'gas'}, {u'tags': [{u'tags': [{u'tags': [{u'tagGroup': u'2sec', u'tags': [{u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'expression': u'', u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWhTON, u'opcItemPath': u'water_Path3', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWhTON', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWhTON', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kW, u'opcItemPath': u'water_Path1', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'engHigh': 10.0, u'name': u'Consumption_kW', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kW', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWh, u'opcItemPath': u'water_Path2', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWh', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWh', u'valueSource': u'opc', u'historyMaxAge': 5}], u'path': Consumption, u'tagType': UdtInstance, u'name': u'Consumption', u'typeId': u'PFRCG12/Electric_v1', u'parameters': {u'OPC Server': {datatype=String, value=EMS PLC}, u'Database': {datatype=String, value=CHA_OT_Historian}}}], u'path': water, u'tagType': Folder, u'name': u'water'}, {u'tagGroup': u'2sec', u'tags': [{u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWh, u'opcItemPath': u'comp_Path2', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWh', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWh', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'expression': u'', u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWhTON, u'opcItemPath': u'comp_Path3', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWhTON', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWhTON', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kW, u'opcItemPath': u'comp_Path1', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'engHigh': 10.0, u'name': u'Consumption_kW', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kW', u'valueSource': u'opc', u'historyMaxAge': 5}], u'path': Consumption, u'tagType': UdtInstance, u'name': u'Consumption', u'typeId': u'PFRCG12/Electric_v1', u'parameters': {u'OPC Server': {datatype=String, value=EMS PLC}, u'Database': {datatype=String, value=CHA_OT_Historian}}}], u'path': compressor, u'tagType': Folder, u'name': u'compressor'}, {u'tags': [{u'tagGroup': u'2sec', u'tags': [{u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'expression': u'', u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWhTON, u'opcItemPath': u'temp_Path3', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWhTON', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWhTON', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWh, u'opcItemPath': u'temp_Path2', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWh', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWh', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kW, u'opcItemPath': u'temp_Path1', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'engHigh': 10.0, u'name': u'Consumption_kW', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kW', u'valueSource': u'opc', u'historyMaxAge': 5}], u'path': Consumption, u'tagType': UdtInstance, u'name': u'Consumption', u'typeId': u'PFRCG12/Electric_v1', u'parameters': {u'OPC Server': {datatype=String, value=EMS PLC}, u'Database': {datatype=String, value=CHA_OT_Historian}}}], u'path': temp, u'tagType': Folder, u'name': u'temp'}], u'path': Electric, u'tagType': Folder, u'name': u'Electric'}], u'path': [default]test_path, u'tagType': Folder, u'name': u'test_path'}]
{u'tags': [{u'tagGroup': u'2sec', u'tags': [{u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'expression': u'', u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWhTON, u'opcItemPath': u'OPC_Path3', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWhTON', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWhTON', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kW, u'opcItemPath': u'OPC_Path1', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'engHigh': 10.0, u'name': u'Consumption_kW', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kW', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWh, u'opcItemPath': u'OPC_Path2', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWh', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWh', u'valueSource': u'opc', u'historyMaxAge': 5}], u'path': Consumption, u'tagType': UdtInstance, u'name': u'Consumption', u'typeId': u'PFRCG12/Electric_v1', u'parameters': {u'OPC Server': {datatype=String, value=EMS PLC}, u'Database': {datatype=String, value=CHA_OT_Historian}}}], u'path': gas, u'tagType': Folder, u'name': u'gas'}
{u'tags': [{u'tags': [{u'tags': [{u'tagGroup': u'2sec', u'tags': [{u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'expression': u'', u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWhTON, u'opcItemPath': u'water_Path3', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWhTON', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWhTON', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kW, u'opcItemPath': u'water_Path1', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'engHigh': 10.0, u'name': u'Consumption_kW', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kW', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWh, u'opcItemPath': u'water_Path2', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWh', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWh', u'valueSource': u'opc', u'historyMaxAge': 5}], u'path': Consumption, u'tagType': UdtInstance, u'name': u'Consumption', u'typeId': u'PFRCG12/Electric_v1', u'parameters': {u'OPC Server': {datatype=String, value=EMS PLC}, u'Database': {datatype=String, value=CHA_OT_Historian}}}], u'path': water, u'tagType': Folder, u'name': u'water'}, {u'tagGroup': u'2sec', u'tags': [{u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWh, u'opcItemPath': u'comp_Path2', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWh', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWh', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'expression': u'', u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWhTON, u'opcItemPath': u'comp_Path3', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWhTON', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWhTON', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kW, u'opcItemPath': u'comp_Path1', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'engHigh': 10.0, u'name': u'Consumption_kW', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kW', u'valueSource': u'opc', u'historyMaxAge': 5}], u'path': Consumption, u'tagType': UdtInstance, u'name': u'Consumption', u'typeId': u'PFRCG12/Electric_v1', u'parameters': {u'OPC Server': {datatype=String, value=EMS PLC}, u'Database': {datatype=String, value=CHA_OT_Historian}}}], u'path': compressor, u'tagType': Folder, u'name': u'compressor'}, {u'tags': [{u'tagGroup': u'2sec', u'tags': [{u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'expression': u'', u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWhTON, u'opcItemPath': u'temp_Path3', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWhTON', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWhTON', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kWh, u'opcItemPath': u'temp_Path2', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'name': u'Consumption_kWh', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kWh', u'valueSource': u'opc', u'historyMaxAge': 5}, {u'tagGroup': u'2sec', u'historyEnabled': True, u'historicalDeadband': 0.0, u'dataType': Float4, u'historicalDeadbandStyle': Discrete, u'sampleMode': OnChange, u'historyProvider': {bindType=parameter, binding={Database}}, u'path': Consumption_kW, u'opcItemPath': u'temp_Path1', u'historyTagGroup': u'20sec', u'historyMaxAgeUnits': MIN, u'tagType': AtomicTag, u'engHigh': 10.0, u'name': u'Consumption_kW', u'opcServer': {bindType=parameter, binding={OPC Server}}, u'GetOpcPath': u'', u'engUnit': u'kW', u'valueSource': u'opc', u'historyMaxAge': 5}], u'path': Consumption, u'tagType': UdtInstance, u'name': u'Consumption', u'typeId': u'PFRCG12/Electric_v1', u'parameters': {u'OPC Server': {datatype=String, value=EMS PLC}, u'Database': {datatype=String, value=CHA_OT_Historian}}}], u'path': temp, u'tagType': Folder, u'name': u'temp'}], u'path': Electric, u'tagType': Folder, u'name': u'Electric'}

can any help me on this please

Attached sample tags for your reference
OPCPath_test.json (3.3 KB)

GetConfiguration won't get you tag paths, it will get you the configuration of tags similar to the output you get from copying a tag's json. Have you tried using tag.browse? That will get you the tag paths (in the fullPath key for each result)

Tag browse only browse the tag paths right?. using configuration we have able to right to the parameters right that's y i chosen this

You can write to udt parameters using tag.write as well. Using getConfiguration with tag.configure to write to udt instances is dodgy if that's what you're doing, as getConfiguration get all non-default values instead of just non-default values set in the UDT instance. Doing this will essentially decouple the UDT instance from its udt type.
I believe you can use exportTags instead which gets you just the non-defaults of the UDT instance, as you would get using copy JSON

One thing is like i have around 600 tags
i like to update all by running a function

If i export tags and manual edit it. it's difficult for me

if you have any idea do this. please give me any example script it will guide me
@JordanCClark any idea from your end?

Hi @nminchin ,

as you said ,
use system.tag.browse - to read all OPC tags
then use system.tag.read to get OPC path
then use system.tag,write - to write it custom property

it will be simple solution

For UDT's i can create custom property in UDT definition. it will reflect in all tags but
One doubt For OPc tags how to create custom property through scripting?

tagConfig ={}
path = '[default]test 1/testing'  # this is opc tag
tagConfig["GetOpcPath"] = "OPC_path1"   #  cusotm property i am trying to create
system.tag.configure(path, [tagConfig], "a")

Do you mean a custom property on a tag? or UDT definition parameters?

For UDT parameters, if you look at a UDT definition's JSON, you'll find your answer.

{
   "name:" "asdasd",
   "parameters": {
      "Param1": {
         "dataType": "String",
         "value": "Val1"
      }
   }
   ...
}

custom property on tag

You have to use something like this:

system.tag.configure(basepath='[default]test 1', tags=[
   {'tags': 
      [
         {'name': 'testing', 'GetOpcPath': 'OPC_path1'}
      ]
   }
]

However, this will replace the tag's configuration with exactly that, removing all other configuration. You either need to use getConfiguration or exportTags to get the existing configuration, then add the GetOpcPath key to that, if you want to keep the existing configuration. I actually thought there was an option to update configuration, but there doesn't seem to be...

1 Like
baseTagPath='[default]test'

tag = {'name': 'testing', 'GetOpcPath': 'OPC_path1'}
 
# Set the collision policy to Abort. Thus, if a tag already exists at the base path,
#    we will not override the tag. If you are overwriting an existing tag, then set this to "o"
collisionPolicy = "m"
 
# Create the tag.
system.tag.configure(baseTagPath, [tag], collisionPolicy)

this script will only create custom property and doesn't remove other existing configuration
collisionPolicy = "m" (this is doing the trick)

1 Like

That's the one, I knew I'd seen it! It's not in the function's helper prompt though..

1 Like

I have to admit I don't understand the point of this exercise. opcItemPath is a tag property. You are trying to copy these values to another tag property (custom) on the same tag. Why can your application not just use the normal tag property?

Tag are in plant server ignition. I am pushing the tags from plant server ignition to Data centre side ignition through MQQT. MQQT doesn't pass the OPC path details to DC side. That's why i am doing like this

I hope you understood now

Ah, so not the same tag, but the tag or reference tag as it appears on the MQTT receiving end. Yes, this makes sense.

1 Like