OPC UA uses StatusCodes to identify the success of operations, including Method calls. However, StatusCodes cannot be extended, and often it is desirable to receive a more detailed application-specific, program-readable reason, why a Method call was not successful.

The following pattern should be used to return application-specific statuses of a Method. The last argument of the output arguments of a Method should contain an application-specific error code. The DataType should be an Integer, preferably an Int32. The information model might provide a description of the values in the Method metadata.

In the following, an example of such a Method definition is given, using the template for Companion Specifications.

If there is an application-specific error in the Method execution, the Method should return an Uncertain StatusCode and the application calling the Method shall only consider the Status output argument of the Method providing the application-specific error code.

Signature

<SomeMethod> (

[in] String <SomeInput>,

[out] UInt32 <SomeOutput>,

[out] Int32 Status);

Table 1 – <SomeMethod> Method Arguments

Argument

Description

<SomeInput>

<description>

<SomeOutput>

<description>

Status

This is an example where the Method needs to return special status information.

0 – OK – Everything is OK

-1 – E_FirstError – Error FirstError occurred

-2 – E_SecondError – Error SecondError occurred

Method Result Codes (defined in Call Service)

Result Code

Description

Uncertain

The value is uncertain. A concrete reason is defined in the Status Output-Argument.

Table 2 – <SomeMethod> Method AddressSpace definition

Attribute

Value

BrowseName

<SomeMethod>

References

NodeClass

BrowseName

DataType

TypeDefinition

Others

HasProperty

Variable

InputArguments

Argument[]

PropertyType

M

HasProperty

Variable

OutputArguments

Argument[]

PropertyType

M

HasArgumentDescription

Variable

Status

Int32

MultiStateValueDiscreteType

M

The InstanceDeclarations of the <some>Type have additional Attributes defined in Table 3.

Table 3 – <some>Type Additional Attributes

Source Path

Value

<SomeMethod>

Status

EnumValues

[{"value":0, "displayName":{"locale":"en", "text":"OK"}, "description":{"locale":"en", "text":"Everything is OK"}},

{"value":-1, "displayName":{"locale":"en", "text":"E_FirstError"}, "description":{"locale":"en", "text":"Error FirstError occurred"}},

{"value":-2, "displayName":{"locale":"en", "text":"E_SecondError"}, "description":{"locale":"en", "text":"Error SecondError occurred"}}]

Note that the last table is defined in the context of the ObjectType <some>Type containing the Method <SomeMethod>.