System.opc.browse perfermance

I have a PLC with +/- 10 000 tags. I search a way to get path and value of each tag with term “config” in the path. I have a functionnal solution but it takes a very long times to do it. (30-40s).

Somebody know a better solution to do it in 3-4 s ??

def create_partConfig_OPC(cellule, cell_config, OPC_server, OPC_parent):
	tags = system.opc.browse(opcServer=OPC_server, folderPath="*" + OPC_parent.rsplit(".",1)[1] + "*", opcItemPath="*config*")
	
	for tag in tags:
		if tag.getType() == "DATAVARIABLE" and not "Document" in str(tag.getDataType()):
			path = tag.getOpcItemPath()
			cell_config[path] = system.opc.readValue(OPC_server, path).getValue()

If you know ahead of time roughly where in the PLC these tags you’re interested in might be then using system.opc.browseServer might be more efficient. system.opc.browse is a poorly implemented and fully recursive browse, so it’s always slow. browseServer on the other hand does no recursion it all; you give it a NodeId to browse, it tells you what’s underneath it, nothing else, if you want to continue browsing then you have to make another call.

There’s an old browseServer example here that might help.

Thanks for the trick. I got error on getNodeId()

object has no attribute ‘getNodeId’

Something weird is going on with this function when called from client/designer. I think it started returning the wrong results somewhere along the way. I need to investigate.

system.opc.browseServer is not a good solution for me. The thing is that I don’t know path I have to reteive. The only thing I know is the server, the start node and that I require the term “config” into the path.

With the system.opc.browseServer it takes +/- 5min to reach all path instead of 35 sec with my solution.

More ideas for me ?

No more ideas then. Run your solution once and save the results somewhere. There’s no generic query/search facility for OPC UA.

Is there a way to simply browse tag group ? I can create a tag group for my config tags then I will have only to browse that group to know the direct path to my OPC ???

Try .getServerNodeId().