How to Browse OPC-UA Servers

This isn't a question, just showing examples about how to browse OPC servers which may be of use in addition to the IA provided documentation. Others can join in to provide other tips and tricks that you find useful.

How to get a list of servers

filt = "RTC"
servers = [s for s in system.opc.getServers() if filt in s]

for s in servers:
	print(s)

How to get a list of top level nodes of interest

Here the part of the string after the square brackets is the node which can be used to explore deeper. Here for example ns=1;i=61357 is the address of the conveyor folder for RTC10.

filt = "RTC"
target = "Conveyor"
servers = [s for s in system.opc.getServers() if filt in s]

conveyorNodes = []
for s in servers:
	tags = system.opc.browseServer(s, None)
	for tag in tags:
		if target in tag.getDisplayName():
			conveyorNodes.append(str(tag.getServerNodeId()))
			
for cn in conveyorNodes:
	print(cn)

How to get asset nodes from within the folder ( in this case, all conveyors in an RTC )

Using the ns=1;i=61357 from above, browse and get the nodes for the conveyors in the area:

tags = system.opc.browseServer("RTC10_MC4", "ns=1;i=61357")
for tag in tags[:10]: # just show the top 10
	print(tag.getDisplayName(), tag.getServerNodeId())

Inside of a single conveyor, see what sub tags exist

Note here this is the same thing as above, just using a different node number

tags = system.opc.browseServer("RTC10_MC4", "ns=1;i=61358")
for tag in tags: 
	print(tag.getDisplayName(), tag.getServerNodeId())

At this point the final tag names can be seen. This is now enough to be able to read from the tag and see what the values are.

Read the value of a tag

tag = system.opc.readValue("RTC10_MC4", "ns=1;s=Objects.Conveyors.Conveyor[9].Name")
print("Conveyor 9 Name: " + tag.value)

With those methods, it is possible to systematically obtain paths and equipment names and systematically create tags or instantiate UDTs.

One additional piece of information that may or may not (probably not) be understandable by looking into OPC-UA is what each bit means. For example in the RunStatusLower is an array of data an inside of OPC-UA it is not clear what each means. In order to know what each means in this case it is necessary to look at the vendors documentation.

Here is what the data looks like from an array pulled as-is from OPC-UA. The values in the array Booleans but its not clear what each one is.

In order to know what each means, it is necessary to have vendor provided documentation. Here it maps out what each bit means. Those meanings can be built into a UDT.

I would probably do another post later on about how to create UDT instances in mass systematically.

Cheers,

Nick

5 Likes