Retain data

This section describes the option to make data available even after an ordered or spontaneous system restart. The NOV-RAM of a device is used for this purpose. The EL6080 cannot be used for these retain data, because the corresponding data must first be transferred, which leads to corresponding runtimes.
The following section describes the retain handler, which stores data and makes them available again, and the application of the different TwinCAT 3 programming languages.

Configuring a retain device

1. The retain data are stored and made available by a retain handler, which is part of the NOV-DP-RAM device in the IO section of the TwinCAT solution. Create a NOV-RAM DP Device in the IO area of the Solution. Retain data 1:
2. Create one or more Retain Handler below this device.
Retain data 2:
Storage location: NOVRAM
3. Configure the NOV-DP RAM device. In the Generic NOV-DP-RAM Device tab, use Search... to define the area to be used.
Retain data 3:
4. An additional retain directory for the symbols is created in the TwinCAT boot directory.

Using the retain handler with a PLC project

In a PLC project the variables are either created in a VAR RETAIN section or identified with the attribute TcRetain.

PROGRAM MAIN 
VAR RETAIN
  l: UINT;
  k: UINT;
END_VAR
VAR
  {attribute ‘TcRetain’:=’1’}
  m: UINT;
  x: UINT;
END_VAR

Corresponding symbols are created after a "Build".
The assignment to the retain handler of the NOV-DP-RAM device is done in column Retain Hdl. Retain data 4:

If self-defined data types (DUTs) are used as retain, the data types must be available in the TwinCAT type system. You can either use the option Convert to Global Type or you can create structures directly as STRUCT RETAIN. However, the Retain Handler then handles all occurrences of the structure.
Retain data cannot be used for POUs (function blocks) as a whole. However, individual elements of a POU can be used.

Using the retain handler with a C++ module

In a C++ module a data area of type Retain Source is created, which contains the corresponding symbols. Retain data 5:

At the instances of the C++ module, a retain handler of the NOV-DP-RAM device to be used for this data area is defined in column Retain Hdl.

Retain data 6:

Conclusions

When a retain handler is selected as target in the respective project, the symbols under retain handler and a mapping are created automatically after a "Build".

Retain data 7: