Methods
Defining Object Methods in the Sterfive OPCUA Modeler YAML File
Methods in OPC UA are defined operations that are part of an Object or ObjectType node. They provide a way to define actions that can be executed, typically involving the object's variables. Methods in Sterfive OPCUA Modeler are defined within the methods
section of an objectTypes
element in the YAML file.
Let's explore the structure in detail:
Method Structure:
objectTypes:
- browseName: MyObjectType
methods:
- browseName: AddTwoValues
inputArguments:
- name: Operand1
dataType: ua:Double
description: The value of operand 1
- name: Operand2
dataType: ua:Double
description: The value of operand 2
outputArguments:
- name: Result
dataType: ua:Double
description: The result of the operation
Here, a method AddTwoValues
is defined under an object type MyObjectType
.
The browseName
attribute of a method represents the method's normative name in the OPC UA node. This is used by OPC UA clients to browse through the tree of nodes via their access path. A node's path within the tree is made up of browseNames.
Methods can have inputArguments
and outputArguments
, which are defined as lists. Each argument in the list has a name
, dataType
, and description
.
The inputArguments
section defines the inputs that the method requires, with each argument having a name
, dataType
(e.g., ua:Double
), and description
. ua:Double
means the argument is a floating-point number defined in the OPC UA namespace.
The outputArguments
section describes the values returned by the method after execution. Like inputArguments
, each outputArguments
item includes a name
, dataType
, and description
. If the method does not return any value, this section can be omitted.
Methods can return multiple values, and in such a case, the outputArguments
section will have multiple elements.
Here's an example of a method returning multiple values:
objectTypes:
- browseName: MyObjectType
methods:
- browseName: CalculateMeanAndStandardDeviation
inputArguments:
- name: ArrayOfValue
dataType: ua:Double
valueRank: 1
description: an array containing the values to transform
outputArguments:
- name: Mean
dataType: ua:Double
description: The mean value of the array
- name: StandardDeviation
dataType: ua:Double
description: The standard deviation value of the array
In this example, the CalculateMeanAndStandardDeviation
method takes an array of doubles as input and returns two output values: the Mean and Standard Deviation of the array.
By defining methods in this way, users can outline various operations related to an ObjectType, providing a flexible and robust means to interact with objects in the OPC UA model.