OPC UA Subscriber Adapter
This adapter establishes a connection to an OPC UA Server and subscribes or cancels data changes or events.
Properties
Operation | Operation executed by the adapter Possible values:
|
Parameters
Adapter | Adapter main class (do not change!) Possible values: de.softproject.integration.adapter.opcua.OpcUaSubscriberAdapter: Main class (default) |
clientAlias | Alias to identify the connection settings Possible values: Any string with the client alias |
process | X4DB path to a Technical Process that is executed after each subscriber reception. Possible values: Any valid X4DB path, e. g. |
url | Server URL Possible values: Any valid URL, e. g. |
user | Username to connect to the server Possible values: Any string with the user name, e.g. |
password | Password to connect to the server Possible values: Any string with the password , e. g. |
security mode | Security Mode and Server Policies Possible values:
|
autoReconnect | Specifies whether the client should automatically reconnect to the server or not. |
Status values
1 | The adapter operation was executed successfully |
-1 | An error occurred while executing the adapter |
Input
Operation Subscribe
Complete example with different subscription types:
Input for the Subscribe operation
XML<?xml version="1.0" encoding="UTF-8"?> <Subscriptions> <!-- Subscription to a data value change --> <Subscription type="DATA_CHANGE" nodeIndex="3" nodeIdentifier="Counter" nodeIdentifierType="String"></Subscription> <!-- Subscription to an event, specifying a condition --> <Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String"> <Field name="SourceName"> <Literal>LIKE</Literal> <Operand>Server</Operand> </Field> </Subscription> <!-- Subscription to an event, specifying more than one condition --> <Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String"> <Field name="ActiveState" attributeId="13"> <Operand>EQUALS</Operand> <Literal>Active</Literal> </Field> <Field name="AckedState" attributeId="13"> <Operand>EQUALS</Operand> <Literal>Unacknowledged</Literal> </Field> <Field name="Comment" attributeId="13"></Field> <Field name="EnabledState" attributeId="13"></Field> <Field name="EventType" attributeId="1"> <Operand>EQUALS</Operand> <Literal>i=9482</Literal> </Field> <Field name="Quality"> <Operand>EQUALS</Operand> <Literal>GOOD (0x00000000) ""</Literal> </Field> <Field name="Severity"> <Operand>LESS_THAN</Operand> <Literal>600</Literal> </Field> <Field name="SourceName"></Field> <Field name="Time"></Field> </Subscription> <!-- Configuring --> <OnAfterCreate>x4db://1/TestingOPCUA/Processes/OnAfterCreate.wrf</OnAfterCreate> <OnAlive>x4db://1/TestingOPCUA/Processes/OnAlive.wrf</OnAlive> </Subscriptions>
Subscribe to data value change:
To subscribe to a data value change, a
Subscription
node must be created with the following mandatory attributes:type
to define the type of subscriptionnodeIndex
,nodeIdentifier
to identify the OPC UA node from which the changes are subscribed tonodeIdentifierType
to specify the data type of the node identifier.
The
Subscription
node can contain the following optional attributes:samplingInterval
: Value in milliseconds with which the OPC UA server samples the data source (PLC).publishingInterval
Value in milliseconds with which the OPC UA server sends the data to the client (e.g. X4).
XML<?xml version="1.0" encoding="UTF-8"?> <Subscriptions> <Subscription type="DATA_CHANGE" nodeIndex="3" nodeIdentifier="Counter" nodeIdentifierType="String" samplingInterval="1000" publishingInterval="1000"> </Subscription> </Subscriptions>
Subscribe to events without specifying fields:
XML<?xml version="1.0" encoding="UTF-8"?> <Subscriptions> <!-- We will receive an empty event --> <Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String"> </Subscription> </Subscriptions
Subscribe to events and specify fields:
XML<?xml version="1.0" encoding="UTF-8"?> <Subscriptions> <!-- In the Field node, we define the field we want to retrieve on each event reception. --> <Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String"> <Field name="SourceName"></Field> <Field name="Time"></Field> </Subscription> <!-- Any number of Field nodes possible. --> </Subscriptions>
Subscribe to events and define filters for the specified fields:
It is possible to define conditions for the attributes that will be received on each event reception. For this purpose, a corresponding number ofField
nodes must be created. EachField
node contains the elementsLiteral
andOperand
.Subscribe event with filters
XML<?xml version="1.0" encoding="UTF-8"?> <Subscriptions> <!-- In the Field node, we define the field we want to retrieve on each event reception. Inside this node Operand and Literal are defined in order to create the condition over the field. --> <Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String"> <!-- Severity less than 600 --> <Field name="Severity"> <Operand>LESS_THAN</Operand> <Literal>600</Literal> </Field> </Subscription> <!-- Any number of Field nodes possible. If there is more than one Field node containing conditions, the logical operator applied between fields will be 'OR' --> </Subscriptions>
Note:
- The
name
attribute withinField
is required. Operand
can have the following values:LESS_THAN
LESS_THAN_OR_EQUALS
GREATER_THAN
GREATER_THAN_OR_EQUALS
EQUALS
NOT
LIKE
Literal
contains the various literal values to be included within the expression.
- The
Operation Unsubscribe
The Un
Subscribe
operation does not require any input, since a cancellation of the subscription is performed. Therefore, only the alias of the client must be specified in the clientAlias
parameter.
Output
Operation Subscribe
The output structure depends on the type of receive message.
When an event is received with fields (with or without conditions) configured in the subscription, the response structure resembles the following sample output:
Output for event responses
XML<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Message type="EVENT"> <Node description="ns=5;s=MyLevel.Alarm"/> <Fields> <Field fieldName="ActiveState">Active</Field> <Field fieldName="AckedState">Unacknowledged</Field> <Field fieldName="Comment">EMPTY</Field> <Field fieldName="EnabledState">Enabled</Field> <Field fieldName="EventType">i=9482</Field> <Field fieldName="Quality">GOOD</Field> <Field fieldName="Severity">500</Field> <Field fieldName="SourceName">MyLevel</Field> <Field fieldName="Time">1576741128000</Field> </Fields> </Message>
Specifying conditions results in more or fewer events being received. However, once an event is received, the response contains the fields specified in the subscription.
If an event is received without field specifications, the response structure resembles the following sample output:
Output for event responses
XML<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Message type="EVENT"/>
If a data value change is received, the response structure resembles the following sample output:
Output for data value changes
XML<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Message type="DATA_CHANGE"> <Node description="ns=3;s=Counter"/> <OldValue> <!-- 0 means null timestamp --> <sourceTimestamp>0</sourceTimestamp> <!-- No value and statusCode present in 'OldValue' node happens only just after subscribing on the first reception --> </OldValue> <NewValue> <sourceTimestamp>13221214634996</sourceTimestamp> <statusCode>GOOD</statusCode> <value>2312.11</value> </NewValue> </Message>
Operation Unsubscribe
The UnSubscribe
operation has no output because the status 1
means that the operation was executed successfully.
Alive Listener Configuration
There is an Alive Listener that allows to configure actions for each live notification of a subscription.
Processes can be defined for the following situations:
After create
: The subscription has been (re)created on the server. This is the case when the subscription timed out due to a communication interruption and needs to be recreated after reconnection.Alive
: The server confirmed that the connection was active, although there were no changes to send.Life timeout
: The server has not confirmed that the connection is active and the life timeout has been exceeded.Timeout
: The server has not confirmed that the connection is active and the maximum keepalive count has been exceeded.
The actions are defined as part of the input XML document as follows:
Input for Subscribe operation
<?xml version="1.0" encoding="UTF-8"?>
<Subscriptions>
<Subscription ...></Subscription>
<Subscription ...></Subscription>
<!-- Alive listener actions -->
<!-- We can define some of them or none, they are not required -->
<OnAfterCreate>x4db://1/TestingOPCUA/Processes/OnAfterCreate.wrf</OnAfterCreate>
<OnAlive>x4db://1/TestingOPCUA/Processes/OnAlive.wrf</OnAlive>
<onLifetimeTimeout>x4db://1/TestingOPCUA/Processes/onLifetimeTimeout.wrf</onLifetimeTimeout>
<onTimeout>x4db://1/TestingOPCUA/Processes/onTimeout.wrf</onTimeout>
</Subscriptions>