Key frames and delta frames
In TwinCAT 3 OPC UA Pub/Sub, data records can be transmitted either as key frames or as delta frames. These mechanisms serve to optimize the network bandwidth and the efficient transmission of process data.
Key frames
A key frame always contains the complete data record of all configured fields of a DataSetMessage. The receiver can reconstruct the complete state of all transmitted variables with a key frame.
Properties of key frames:
- Always contain all fields of the DataSet.
- Enable synchronization of the complete state.
- Are sent regularly to ensure that a subscriber receives a consistent state even after packet loss.
Key frames thus form the reference basis for subsequent delta frames.
Delta frames
A delta frame only contains the values of the fields whose content has changed since the last frame sent. This reduces the size of the transmitted messages, especially if only a few variables change within a DataSet.
Properties of delta frames:
- Only transmit changed fields.
- Reduce network load and bandwidth utilization.
- Can only be interpreted if a valid key frame has been received beforehand.
A subscriber must therefore first receive a key frame before delta frames can be applied correctly.
Interaction of key frames and delta frames
When delta frame functionality is activated, the publisher typically sends a sequence of delta frames that is regularly interrupted by a key frame.
This ensures that:
- lost packets can be compensated.
- a subscriber can be synchronized again at any time.
The frequency of the key frames is determined via the "KeyFrameCount" parameter.
In the case of UADP, there is a special feature in the interaction of key frames and delta frames: If all fields of a data record change, then a key frame must be sent. Even if the delta frame is larger than the key frame (possible due to the coding), a key frame must be sent.
Parameter: KeyFrameCount
The KeyFrameCount parameter defines after how many sent messages a key frame is transmitted again.
Example:
KeyFrameCount = 3In this case:
- a key frame is sent.
- followed by up to two delta frames.
- then a key frame again.
The sequence therefore looks as follows, for example:
Key, Delta, Delta, Key, Delta, ...Smaller values for "KeyFrameCount" mean that a complete data set is transmitted more frequently, which increases robustness but also increases the network load.
Parameter: KeepAliveInterval
The KeepAliveInterval parameter ensures that messages are transmitted even if no values in the DataSet have changed.
This is particularly relevant when using delta frames, as otherwise no messages would be sent without changes.
When the KeepAlive interval is reached, the publisher sends a message, even if there are no field changes. The purpose of this message is:
- to keep the connection active.
- to signal to the subscriber that the publisher is still active.
- to avoid timeouts or watchdog mechanisms.
Depending on the implementation, this message can be transmitted as a key frame or as a frame without field changes.
Summary
The combination of key frames, delta frames, KeyFrameCount and KeepAliveInterval enables efficient and robust data transmission:
- Key frames transmit the complete state.
- Delta frames only transmit changes.
- KeyFrameCount defines the maximum number of delta frames between two complete state transmissions.
- KeepAliveInterval ensures that messages are sent regularly even if the data has not changed.
Through suitable parameterization, an optimal compromise between bandwidth consumption and system robustness can be achieved.
The following diagram illustrates these relationships once again.
