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.
Method nodes are 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β
| Type | Parameter | Description |
|---|---|---|
| String | opcServer | The name of the OPC server connection. |
| String | nodeId | The node ID to browse. |
Returnsβ
List - A list of PyOPCTagEx objects.
Scopeβ
Gateway
Syntax - Vision Client Scopeβ
system.opc.browseServer(opcServer, nodeId)
Parametersβ
| Type | Parameter | Description |
|---|---|---|
| String | opcServer | The name of the OPC server connection. |
| String | nodeId | The node ID to browse. |
Returnsβ
List - A list of OPCBrowseElement objects.
Scopeβ
Vision Client, Perspective Session, Designer
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.
- 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.
- 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.
- getDataType() - Returns data type information.
- New in 8.3.1getDescription() - Returns a description of the OPC tag in the specified node ID.
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 an object, try to browse deeper.
if (elementType == 'OBJECT' and depth < maxDepth):
browse(childNodeId, depth + 1)
system.util.invokeAsynchronous(partial(browse, root))