Skip to main content
Version: 8.1

system.opc.browseServer

This function is used in Python Scripting.

Description​

When called from a Vision Client, Perspective Session, or the Designer, returns a list of OPCBrowseElement objects for the given server. Otherwise returns a list of PyOPCTagEx objects.

New in 8.1.8
As of 8.1.8, method nodes are now included in the browse results. Methods can be read and subscribed to, but not written to.

Client Permission Restrictions​

This scripting function has no Client Permission restrictions.

Syntax​

system.opc.browseServer(opcServer, nodeId)

Parameters​

TypeParameterDescription
StringopcServerThe name of the OPC server connection.
StringnodeIdThe node ID to browse.

Returns​

List - A list of PyOPCTagEx objects.

Scope​

Gateway, Perspective Session

Syntax - Vision Client Scope​

system.opc.browseServer(opcServer, nodeId)

Parameters​

TypeParameterDescription
StringopcServerThe name of the OPC server connection.
StringnodeIdThe node ID to browse.

Returns​

List - A list of OPCBrowseElement objects.

Scope​

Vision Client

Object Summary​

The OPCBrowseElement object has the following methods:

  • getDisplayName() - Returns the display name of the object.
  • getElementType() - Returns the element type. Element types are server, device, view, folder, object, datavariable, property and method.
  • ​
    New in 8.1.20
    getNodeId() - Returns a string representing the server node ID. Functionally similar to getServerNodeId(), except it is available in all scopes, not just the Client/Designer.
  • ​
    New in 8.1.1
    getDatatype() - Returns data type information.

The PyOPCTagEx object has the following methods to retrieve information:

  • getDisplayName() - Returns the display name of the object.
  • getElementType() - Returns the element type. Element types are server, device, view, folder, object, datavariable, property and method.
  • getServerName() - Returns the server name as a string.
  • getNodeId() - Returns a string representing the server node ID.
  • ​
    New in 8.1.1
    getDataType() - Returns data type information.

Code Examples​

Example #1
# Print the name of all devices on Ignition OPC-UA
opcServer="Ignition OPC-UA Server"
nodeId = "Devices"
devices = system.opc.browseServer(opcServer, nodeId)
for device in devices:
print device.getDisplayName()
Example #2
# Print the object's server node ID
# This method call works in all scopes (Client, Gateway, and Perspective)
opcServer = "Ignition OPC UA Server"
nodeId = "Devices"
results = system.opc.browseServer(opcServer, nodeId)
for result in results:
print "NodeID: ", result.getServerNodeId()
Example #3 - Recursive Browse
# This example attempts to recursively browse OPC nodes. Be mindful of the maxDepth in larger systems.
# The example uses system.util.getLogger asynchronously, so if you're calling this in the Script Console,
# the output may appear in a different console (i.e., Designer console).

from functools import partial

maxDepth = 1 # Determines how deep the browse will go
serverName = 'Ignition OPC UA Server'
myLogger = system.util.getLogger('My Browse') # Creating a logger to print the results

# Determines where the browse should start. An empty string will start at the root.
# Alternatively, '[device name]' will start at a certain device.
root = ''

def browse(nodeId, depth = 0):
children = system.opc.browseServer(serverName, nodeId)

for child in children:
elementType = str(child.getElementType())
childNodeId = child.getServerNodeId().getNodeId()

msg = 'Depth - %s, Node - %s' % (depth, childNodeId)
myLogger.info(msg)

# If the element is a folder, try to browse deeper.
if (elementType == 'FOLDER' and depth < maxDepth):
browse(childNodeId, depth + 1)

system.util.invokeAsynchronous(partial(browse, root))

Keywords​

system opc browseServer, opc.browseServer