OPC UA Client - Methods
The WinCC OA client supports the usage of OPC UA methods. It can be used to establish in- and outbound communication with OPC UA server methods via data point elements.
Functionality
The method communication is performed via the periphery address of a data point element. Here, the data is transmitted using a JSON string.
Method Call
During a method call, a consistent data set with input parameters is sent to the server.
The response also consists of a consistent data set.
Method Call Workflow
To implement a standard interface for all methods, the input parameters are passed to the client as a JSON string.
The client also sends the return values in a JSON string.
Data point elements - Input / Output
For the communication between client and server via OPC UA methods it is required to configure two data point elements so that one is used for transmitting method calls and one DPE is configured to receive the return values of the method. The two address configurations must be identical except for their "Direction".
By setting a specific JSON string to the output address the server method is called and the return value and additional output is returned to the input DPE.
To configure an OPC UA address configuration for using OPC UA methods the corresponding checkbox within the configuration panel must be selected.
In addition the button "Get Item ID" can be used to select the desired server method.
OPC UA Methods Output/Input AddressJSON Structure
The structure of the JSON string differs between inbound and outgoing messages.
JSON-String Output Address
- input 1..n - List of parameters, which is passed to the server method. They use
the format
"<id>_<datatype>":<value>
where the id starts with 1 and the data type is stated as integer value, e.g."1_757":1,"2_757":51
- userdata - A free field, which can be used to state user specific information.
The element is retured within the response of the server and can be used as
RequestID, e.g.
"userdata":29689
- timeout - Maximum time (in milliseconds) that is waited for the reply of the
server to the input address (optional), e.g.
"timeout":100
The full JSON string on the DPE for the examples stated above looks as follows:
{"1_757":1,"2_757":51,"userdata":29689}
.
JSON-String Input Address
- result - The "result" returns the OPC UA statuscode. The format
"0_<datatype>":"<value>"
is used, e.g."0_762":"0-Good"
- output 1..n - The output values of the method are transfered as separate
elements within the JSON string and use the format
"<id>_<datatype>":<Value>
. The ID corresponds to the position of the return value and the data type is stated as integer value, e.g.
."1_762":"Slept for 299 mili seconds."
- userdata - Returns the information of the "userdata" element of the output
address, e.g.
"userdata":29689
The full JSON string on the DPE for the examples stated above looks as follows:
{"0_762":"0-Good","1_762":"Slept for 299 milliseconds.","userdata":29689}
Example
A complete example for using the OPC UA methods can be found within the chapter OPC UA Methods Example.
Notes
Consider following information:
- The types listed below cannot be used as method parameters as they cannot be
handled by standard JSON types with standard variable conversions.
- int64
- uint64
- date time
- guid
- byte string
- xml element
- node id
- localized texts