API to return nodes by searching

Introduction

The APIs described below return C# objects corresponding to OPC UA nodes of the project. Unlike Get APIs, it is not necessary to know and/or specify the exact node in which to search the node to return. In fact, the nodes are searched among all the child nodes of a known node, at any level of its structure.

Note

compared to the execution of a Get API, in which the exact path of the node to return is specified, the execution of a Find API is slower. Also, when there are multiple child nodes with the same name, an unwanted node can be returned.

Find APIs are supplied by the IUANode class, whose instances are the starting point for searching the nodes to return.

IUANode.Find(browseName)

Returns an IUANode C# object, corresponding to the first child node found among all the node children on which the method is invoked, and named as the argument.

IUANode Find(string browseName);

Arguments

browseName string

BrowseName of the node to find.

Returns

IUANode

C# object corresponding to the node found.

Example

Below is an example in which the API returns a C# object corresponding to the first Speed node child of the model node:

var model = Project.Current.Get("Model");
var speed = model.Find("Speed");

IUANode.FindObject(browseName)

Returns an IUAObject C# object, corresponding to the first child object found among all the node children on which the method is invoked and named as the argument.

IUAObject FindObject(string browseName);

Arguments

browseName string

BrowseName of the object to find.

Returns

IUANode

C# object corresponding to the object found.

Example

Below is an example in which the API returns a C# object corresponding to the first Motor object child of the project root node:

var motor = Project.Current.FindObject("Motor");
var currentSpeed = motor.GetVariable("Speed").Value;

IUANode.FindVariable(browseName)

Returns an IUAVariable C# object, corresponding to the first child variable found among all the node children on which the method is invoked and named as the argument.

IUAVariable FindVariable(string browseName);

Browse arguments

browseName string

BrowseName of the variable to find.

Returns

IUANode

C# object corresponding to the variable found.

Example

Below is an example in which the API returns a C# object corresponding to the first Speed variable child of the project root node:

var currentSpeed = Project.Current.FindVariable("Speed");

IUANode.Find<T>(browseName)

Returns an C# object corresponding to the first child node among all the node children on which the method is invoked, named as the argument and of the specified type.

Note

specifying an exact type (<T>) improves the IntelliSense in the code editor. When writing the code, it also allows errors to be identified, while at runtime it is evident if the node searched is of the requested type or not (if not, the API returns null).

T Find<T>(string browseName);

Arguments

T

IUANode C# class corresponding to the C# object class to return.

browseName string

BrowseName of the node to find.

Returns

T

C# object corresponding to the node found.

Examples

Below is an example in which the API returns a C# object corresponding to the first Motor1 node child of the node that contains the NetLogic:

var motor = Owner.Find<Motor>("Motor1");
var currentSpeed = motor.Speed;

IUANode.FindByType<T>()

Returns a C# object corresponding to the first child node among all the node children on which the method is invoked and of the specified type.

Note

specifying an exact type (<T>) improves the IntelliSense in the code editor. When writing the code, it also allows errors to be identified, while at runtime it is evident if the node searched is of the requested type or not (if not, the API returns null).

T FindByType<T>();

Arguments

T

IUANode C# class corresponding to the C# object class to return.

Returns

T

C# object corresponding to the node found.

Example

Below is an example in which the API returns a C# object corresponding to the first Motor node child of the project root node:

var motor = Project.Current.FindByType<Motor>();

IUANode.FindNodesByType<T>()

Returns an IEnumerable C# list, corresponding to the list of all the child nodes of the node on which the method is invoked and of the specified type.

Note

specifying an exact type (<T>) improves the IntelliSense in the code editor. When writing the code, it also allows errors to be identified, while at runtime it is evident if the node searched is of the requested type or not (if not, the API returns null).

IEnumerable<T> FindNodesByType<T>();

Arguments

T

IUANode C# class corresponding to the C# object class to return.

Returns

IEnumerable

C# list containing the nodes of the requested type.

Example

Below is an example in which the API returns a list of all the nodes of Motor type in the project:

var motors = Project.Current.FindNodesByType<Motor>();

See also

Related concepts

Access to project nodes

C# project nodes

Related APIs

API to return known nodes