Reading variables

Variable values can be read from an OPC UA server via the TwinCAT OPC UA I/O Client. The values can be sampled using various mechanisms, which are described in more detail below.

The various settings in this context are made in the configuration pages of the I/O device. The Process Data Configuration area shows various parameters for setting the different modes of data collection from a server.

The TwinCAT OPC UA I/O Client offers three different modes for data collection:

Polling (cyclic reading/writing)

One of the possible types of data collection is cyclic reading and writing. Time intervals are defined for both reading and writing. You can also specify how many variables are to be read in one read command.

Reading variables 1:

Writing variables in polling and subscription mode

When writing, please note that writing only takes place when the value changes. If no value change has taken place in the configured variables at the end of a cycle, no new value is written.

Reading variables 2:

Parameter

Description

Read Cycle Time

Specifies how fast variables are cyclically read.

Write Cycle Time

Defines how often a write command is triggered on the OPC UA channel. If a variable value changes several times within a specific cycle time, only the last value is written to the OPC UA channel. If no configured value has changed in the cycle time, no write command is triggered.

ReadList

Read commands on the OPC UA channel are bundled to save bandwidth. This parameter specifies how many variables are collected in a single read command on the OPC UA channel. The labeling behind it indicates how many read commands arise from the current configuration.

Array Single Write

If a value in an array is changed, a write operation is only carried out for this value on the OPC UA channel when activated. If not activated, the entire array is always written.

OnTrigger

In addition, there is an option to trigger reading and writing via trigger variables. For each OPC UA Client device there is a trigger variable (it can be found under Outputs/Control/Execute) that can be connected to a variable from the PLC and set if required. This option is suitable, for example, if data is only to be read from an OPC UA Server when a certain event occurs in the PLC. If the trigger variable remains permanently set, the data collection type behaves in the same way as the cyclic configuration.

When writing, on the other hand, a value is written in each cycle if the trigger variable is set. No change in value is considered here.

Reading variables 3:

Subscriptions

The third and last way of data collection is to use subscriptions. The I/O client registers a subscription with the connected OPC UA Server. The parameters described below can be specified for Publish Interval, Lifetime Count and Keepalive Count.

Subscription mode is primarily intended for reading variables. If you write values in this mode, the same behavior applies as for cyclical writing (see above).

Reading variables 4:

Parameter

Description

Publish Interval

After the specified time the connected OPC UA Server checks where there are new notification packets for the Client. If several value changes occur in a publishing interval, only the last value is transferred.

Lifetime Count

The OPC UA Client is responsible for sending a PublishRequest to the server. In the PublishResponse, the server returns the respective notification packages. The Lifetime Count indicates after how many failed PublishRequests from the client the server deletes the subscription. The calculated duration is shown in brackets (in the sample 1200 multiplied by 1000 ms = 20 minutes).

Keepalive Count

If the server does not have new notification packets for the client, it will not return any data. The Keepalive Count indicates after how many missed messages the server would send an empty message to the client to indicate that it is still active and the subscription is still in place.