API to create variables

Introduction

The APIs described below create variables in the Q Studio project and return the corresponding C# objects. They are supplied by the InformationModel class, displayed by the QPlatform.HMIProject module.

InformationModel.MakeAnalogItem(browseName, dataTypeId)

Create a project analog variable derived from the AnalogItemType, which contains the data type indicated and returns a corresponding IUAVariable C# object.

static IUAVariable MakeAnalogItem(QualifiedName browseName, NodeId dataTypeId);

Arguments

browseName QualifiedName

BrowseName of the new variable.

dataTypeId NodeId

Data type contained in the new variable.

Note

it is represented by a node inside the DataTypes classes (e.g.:OpcUa.DataTypes.Boolean).

Returns

IUAVariable

Corresponding C# object to the project variable created.

Example

Below is an example in which an analog variable, MyAnalogVar, is created which contains a float data type:

var myVar = InformationModel.MakeAnalogItem("MyAnalogVar", OpcUa.DataTypes.Float);
Owner.Add(myVar);

InformationModel.MakeVariable(browseName, dataTypeId, arrayDimensions)

Creates a project variable derived from the BaseDataVariableType (base variable), which contains the data type indicated by the second argument and returns a corresponding IUAVariable C# object. Using the third argument (optional), it is possible to create an array, specifying its type and size.

static IUAVariable MakeVariable(QualifiedName browseName, NodeId dataTypeId, uint[] arrayDimensions);

Arguments

browseName QualifiedName

BrowseName of the new variable.

dataTypeId NodeId

Data type contained in the new variable.

Note

it is represented by a node inside the DataTypes classes (e.g.:OpcUa.DataTypes.Boolean).

arrayDimensions uint[ ]

Optional. Array size.

Returns

IUAVariable

Corresponding C# object to the project variable created.

Examples

Below is an example in which an analog variable, MyVar, is created, which contains a floating data:

var myVar = InformationModel.MakeVariable("MyVar", OpcUa.DataTypes.Float);
Owner.Add(myVar);

Below is an example in which a MyArray array with three cells is created:

var arrayDimensions = new uint[1];
arrayDimensions[0] = 3
var myVar = InformationModel.MakeVariable("MyArray", OpcUa.DataTypes.Int32, arrayDimensions);
Owner.Add(myVar);

InformationModel.MakeVariable(browseName, dataTypeId, variableTypeId, arrayDimensions)

Create a project variable of the type indicated by the third argument, and which contains the data type indicated by the second argument. It returns a C# object of the IUAVariable type corresponding to the project variable created. Using the fourth argument (optional), it is possible to create an array, specifying its type and size.

static IUAVariable MakeVariable(QualifiedName browseName, NodeId dataTypeId, NodeId variableTypeId, uint[] arrayDimensions);

Arguments

browseName QualifiedName

BrowseName of the new variable.

dataTypeId NodeId

Data type contained in the new variable.

Note

it is represented by a node inside the DataTypes classes (e.g.:OpcUa.DataTypes.Boolean).

variableTypeId NodeId

Variable type from which the new variable is derived.

Note

it is represented by a node inside the VariableTypes classes (e.g.: QPlatform.CoDeSys.VariableTypes.Tag).

arrayDimensions uint[ ]

Optional. Array size.

Returns

IUAVariable

Corresponding C# object to the project variable created.

Example

In the following example, a Tag2 variable of the CoDeSysTag native type is created, that contains one Int32 data:

var myVar = InformationModel.MakeVariable("Tag2", OpcUa.DataTypes.Int32, QPlatform.CoDeSys.VariableTypes.Tag);;
Owner.Add(myVar);

InformationModel.MakeVariableType(browseName, dataTypeId, arrayDimensions)

Create a project variable type derived from the BaseDataVariableType (base variable) type, which contains the data type indicated by the second argument and returns a C# object of the corresponding IUAVariableType type. Optionally, it is possible to create an array, specifying its size with the third argument.

static IUAVariableType MakeVariableType(QualifiedName browseName, NodeId dataTypeId, uint[] arrayDimensions);

Arguments

browseName QualifiedName

BrowseName of the new variable type.

dataTypeId NodeId

Data type contained in the new variable type.

Note

it is represented by a node inside the DataTypes classes (e.g.:OpcUa.DataTypes.Boolean).

arrayDimensions uint[ ]

Optional. Array size.

Returns

IUAVariableType

C# object matching the project variable type created.

Example

Below is an example in which a MyVarType variable is created, which contains an Int32 data:

var myVar = InformationModel.MakeVariableType("MyVarType", OpcUa.DataTypes.Int32);
Owner.Add(myVar);

InformationModel.MakeVariableType(browseName, dataTypeId, variableTypeId, arrayDimensions)

Create a project variable of the type indicated by the third argument (supertype), and which contains the data type indicated by the second argument. It returns a C# object of the IUAVariableType corresponding to the project variable type created. Using the fourth argument (optional), it is possible to create an array, specifying its type and size.

static IUAVariableType MakeVariableType(browseName QualifiedName, NodeId dataTypeId, NodeId variableTypeId, uint[] arrayDimensions);

Arguments

browseName QualifiedName

BrowseName of the new variable type.

dataTypeId NodeId

Data type contained in the new variable type.

Note

it is represented by a node inside the DataTypes classes (e.g.:OpcUa.DataTypes.Boolean).

variableTypeId NodeId

Variable type from which the new variable type is derived.

Note

it is represented by a node inside the VariableTypes classes (e.g.: QPlatform.CoDeSys.VariableTypes.Tag).

arrayDimensions uint[ ]

Optional. Array size.

Returns

IUAVariableType

C# object matching the project variable type created.

Example

Below is an example in which a MyTagType variable type derived from the CoDeSysTag native type is created, and which contains one Int32-type data:

var myVar = InformationModel.MakeVariableType("MyTagType", OpcUa.DataTypes.Int32, QPlatform.CoDeSys.VariableTypes.Tag);
Owner.Add(myVar);

InformationModel.MakeVariable<T>(browseName, dataTypeId, arrayDimensions)

Create a project variable, derived from the specified <T> type, which contains the data type indicated by the second argument. It returns a C# object of the specified <T> type corresponding to the project variable created. Using the third argument (optional), it is possible to create an array, specifying its type and size.

Note

at design time, the API functions only if the specified type is a native type, i.e., contained in the Q Platform modules.

static T MakeVariable<T>(QualifiedName browseName, NodeId dataTypeId, uint[] arrayDimensions);

Arguments

T

IUAVariable C# class, corresponding to the C# object class to return and to the variable type from which the new variable is derived.

browseName QualifiedName

BrowseName of the new variable.

dataTypeId NodeId

Data type contained in the variable.

Note

it is represented by a node inside the DataTypes classes (e.g.:OpcUa.DataTypes.Boolean).

arrayDimensions uint[ ]

Optional. Array size.

Returns

IUAVariable

Corresponding C# object to the project variable created.

Examples

Below is an example in which a Speed2 variable of the Speed type is created and returns a Speed C# object:

var myVar = InformationModel.MakeVariable<Speed>("Speed2", OpcUa.DataTypes.Int32);
Owner.Add(myVar);

InformationModel.MakeVariable<T>(browseName, variableTypeId, dataTypeId, arrayDimensions)

Creates a project variable of the type indicated by the third argument, and which contains the data type indicated by the second argument. It returns a C# object of the specified <T> type corresponding to the project variable created. Using the fourth argument (optional), it is possible to create an array, specifying its type and size.

static T MakeVariable<T>(QualifiedName browseName, NodeId variableTypeId, NodeId dataTypeId, uint[] arrayDimensions);

Arguments

T

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

browseName QualifiedName

BrowseName of the new variable.

variableTypeId NodeId

Variable type from which the new variable is derived.

Note

it is represented by a node inside the VariableTypes classes (e.g.: QPlatform.CoDeSys.VariableTypes.Tag).

dataTypeId NodeId

Data type contained in the variable.

Note

it is represented by a node inside the DataTypes classes (e.g.:OpcUa.DataTypes.Boolean).

arrayDimensions uint[ ]

Optional. Array size.

Returns

IUAVariable

Corresponding C# object to the project variable created.

Example

var myTag = InformationModel.MakeVariable<QPlatform.CoDeSys.Tag>("CodesysTag", OpcUa.DataTypes.UInt16);

InformationModel.MakeVariableType<T>(browseName, variableTypeId, dataTypeId, arrayDimensions)

Create a project variable type derived from the type indicated by the third argument (supertype), and which contains the data type indicated by the second argument. Returns a C# object of the specified <T> type corresponding to the project variable type created. Using the fourth argument (optional), it is possible to create an array, specifying its type and size.

static T MakeVariableType<T>(QualifiedName browseName, NodeId variableTypeId, NodeId dataTypeId, uint[] arrayDimensions);

Arguments

T

IUAVariableType C# class, corresponding to the C# object class to return.

browseName QualifiedName

BrowseName of the new variable type.

variableTypeId NodeId

Variable type from which the new variable is derived.

Note

it is represented by a node inside the VariableTypes classes (e.g.: QPlatform.CoDeSys.VariableTypes.Tag).

dataTypeId NodeId

Data type contained in the new variable type.

Note

it is represented by a node inside the DataTypes classes (e.g.:OpcUa.DataTypes.Boolean).

arrayDimensions uint[ ]

Optional. Array size.

Returns

IUAVariable

C# object corresponding to the project variable type created.

Example

var myCustomTagType = InformationModel.MakeVariableType<QPlatform.CoDeSys.TagType>("CustomCoDeSysTagType", QPlatform.CoDeSys.VariableTypes.Tag, OpcUa.DataTypes.UInt16);

See also

Related concepts

Variables

Related procedures

Variables and Variable Types