Skip to main content

Retain Data in Shared Memory

Some products do not include an automatic connection of retain data from the application in the controller (due to a lack of generally valid storage options). However, there is an existing mechanism in the runtime system by means of a connection via shared memory (SHM) which can be used for this purpose with a respective configuration.

Usage is possible, for example, with the following CODESYS Control SL products:

  • CODESYS Control​ for Linux

  • CODESYS Control for Linux ARM

  • CODESYS Control for Linux ARM64

  • CODESYS Control for Raspberry Pi

  • CODESYS Control for BeagleBone

Version note: The minimum version of the CODESYS Control SL product is V4.4.0.0 (CODESYS Control version 3.5.17.30)

Basically, "Retains" are enabled via SHM by the following settings in /etc/CODESYSControl_User.cfg on the target device:

[CmpApp]
 RetainType.Applications=InSHM
[CmpRetain]
 Retain.SHM.Size=0x1FFFF        ; Total size of remanent memory in bytes
 Retain.SHM.Name=MyRetainMemory ; Optional (Default: "RetainMemory")

After a restart, the runtime system creates a shared memory file with the configured name under /dev/shm. By mapping this file, the memory can be redirected to any non-volatile file, for example, by the following commands:

sudo touch /dev/shm/MyRetainMemory
sudo mount -o bind /var/opt/MyRetainMemory /dev/shm/MyRetainMemory

Important

The file is accessed cyclically according to the cycle time set in the PLC application. The SHM file should therefore never be redirected to a file in a flash-based file system, otherwise there is a risk that the memory will be destroyed.