Creating a Retain Handler

Under TwinCAT 3 (from Build 4020) a delta algorithm is used to save data in the NOVRAM. The algorithm does not save all the variables in the NOVRAM. Instead, it searches for changes (delta function) compared to the previous cycle and only saves variables that have changed.

To use the delta algorithm, a Retain Handler must be created in TwinCAT 3, and the relevant variables must be declared in the PLC with the keyword VAR_RETAIN.

A new feature of this method is that no function blocks have to be used. The Retain Handler saves data in the NOVRAM in the event of a power failure and makes them available again once the power has been restored.

This chapter describes how to create a Retain Handler in TwinCAT 3. The Retain Handler saves data in the NOVRAM and makes them available again. In other words, important variable values such as production data or counter values are retained during a restart or power failure.

Requirements for this step:

Create the Retain Handler as follows:

1. Right-click on Devices in the tree view on the left-hand side.
2. In the context menu click on Scan.
Creating a Retain Handler 1:
3. Select Device (NOV-DP-RAM) and confirm with OK.
Creating a Retain Handler 2:
4. Click on Yes to search for boxes.
5. Click on Device (NOV-DP-RAM) in the tree view on the left-hand side and then on the tab Generic NOV-DP-RAM Device.
Creating a Retain Handler 3:
6. Click the option PCI.
7. Right-click on Device (NOV-DP-RAM) in the tree view and then on Add New Item.
Creating a Retain Handler 4:
8. Select the Retain Handler and click on OK.
Creating a Retain Handler 5:
You have successfully created a Retain Handler in TwinCAT.
Creating a Retain Handler 6:
In the next step you can create retain variables in the PLC and link them with the Retain Handler.