API to return known nodes

Introduction

The APIs described below return C# objects that correspond to OPC UA nodes of the project, starting from nodes for which the name or type from which they are derived are known. These APIs are supplied by the IUANode class, whose instances are starting points for searching nodes to return.

Note

if there are several nodes with the same name, they can return an unwanted node.

IUANode.Get(browsePath)

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

IUANode Get(string browsePath);

Arguments

browsePath string

BrowseName of the node or path of the node in the information model, uniquely expressed as a sequence of BrowseNames separated by /.

Returns

IUANode

C# object that matches the requested node.

Examples

Below are two examples where the API returns a C# object corresponding to the Motor1 node, child of Machine1:

var motor1 = Owner.Get("Machine1").Get("Motor1");
var motor1 = Owner.Get("Machine1/Motor1");

IUANode.GetObject(browsePath)

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

IUAObject GetObject(string browsePath);

Arguments

browsePath string

BrowseName of the object or the path of the object in the information model, uniquely expressed as a sequence of BrowseNames separated by /.

Returns

IUAObject

C# object that matches the requested object.

Examples

Here are two examples where the API returns a C# object corresponding to the Motor1 object:

var motor1 = Owner.GetObject("Machine1").GetObject("Motor1");
var motor1 = Owner.GetObject("Machine1/Motor1");

IUANode.GetVariable(browsePath)

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

IUAVariable GetVariable(string browsePath);

Arguments

browsePath string

BrowseName of the variable or path of the variable in the information model, uniquely expressed as a sequence of BrowseNames separated by /.

Returns

IUAVariable

C# Object that matches the requested variable.

Examples

Here are two examples where the API returns a C# object corresponding to the Speed variable of the Motor1 object:

var currentSpeed = Project.Current.GetObject("Motor1").GetVariable("Speed")
var currentSpeed = Project.Current.GetVariable("Motor1/Speed");

IUANode.Get<T>(browsePath)

Returns a C# object that matches the first child node of the node on which this method is invoked with its name matching the argument 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 Get<T>(string browsePath);

Arguments

T

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

browsePath string

BrowseName of the node or path of the node in the information model, uniquely expressed as a sequence of BrowseNames separated by /.

Returns

T

C# object that matches the requested node.

Example

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

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

IUANode.GetByType<T>()

Returns C# object that matches the first child node of the node on which the method is invoked and of the specified type T .

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 GetByType<T>();

Arguments

T

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

Returns

T

C# object that matches the requested node.

Example

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

var myMotor = Owner.GetByType<Motor>();

IUANode.GetNodesByType<T>()

Returns an IEnumerable C# list, corresponding to the list of 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> GetNodesByType<T>();

Arguments

T

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

Returns

IEnumerable

C# list containing the nodes of the requested type.

Example

var model = Project.Current.Get("Model");
var motors = model.GetNodesByType<Motor>();

IUANode.GetAlias(aliasName)

Returns a C# object corresponding to the node pointed to by the alias indicated as the argument.

IUANode GetAlias(string aliasName);

Arguments

aliasName string

BrowseName of the alias or path of the node in the information model, uniquely expressed as a sequence of BrowseNames separated by /.

Returns

IUANode

C# object that matches the requested node.

Example

Below is an example where the API returns a C# object corresponding to the node pointed to by the Alias1: alias:

var modelFolder = Project.Current.Get("Model");
var alias = modelFolder.GetAlias("Alias1");