Access to project nodes

Introduction: access to members of an object in C#

In C#, each property or method contained in an object is generically defined as a member of the object. Each member is identified by the BrowseName of the matching project node.

Note

to display the BrowseName of a property in the Property panel, position the pointer over its name: a tooltip appears with the BrowseName, data type, and short description (if present).

To access the members in hierarchical order, use the point. In the following examples, a Motor object and its Acceleration and Speed properties are accessed.

Motor.Acceleration = 123;

In this example, the value of the Motor object Acceleration property is set to the value 123.

int currentSpeed = Motor.Speed;

In this example, the value of the Motor object Speed property is assigned to the value of the currentSpeed C# integer variable.

Access to the OPC UA nodes of a Q Studio project

To access a node in the C# information model, this node must be represented in the NetLogic by a matching C# object. To obtain this C# object, the following APIs can be used:

To refer to the OPC UA nodes of the properties of an object (see Properties), the name of the matching C# property consists of the BrowseName of the property to which the “Variable” suffix is added. Below is an example in which a dynamic link is set on the Text property of a label through API, accessing the property node represented by TextVariable (see API for dynamic links):

Label1.TextVariable.SetDynamicLink(speedValue);

LogicObject Variable: direct access to the NetLogic object

Each NetLogic displays the LogicObject variable, which represents the same NetLogic node. It is useful for directly accessing the node without writing additional code.

In the following example, the value of the Speed variable contained in the NetLogic is set to 100:

LogicObject.GetVariable("Speed").Value = 100;

In the following example, the value of the Speed variable is assigned to the speed C# integer variable:

int speed = LogicObject.GetVariable("Speed").Value;

Variable Owner: direct access to the NetLogic parent object

Each NetLogic displays the Owner variable, which represents the parent node of the same NetLogic. It is useful for directly accessing this node without writing additional code.

In the following example, the value of the NetLogic parent node BrowseName is assigned to the C# name string variable:

string name = Owner.BrowseName;

Variable Session: directly access the session alias

Each NetLogic displays the Session variable, which represents the session node. It is useful for directly accessing this node to read or modify the session properties (see Session nodes).