Other AdaptionΒΆ

%MB area as RETAIN

As it is not possible to retain the data in %MB area in eCo CPUs, some changes must be done to achieve that. One way to do that is to copy the data from %MB area (2kB) to %RB area (1kB) and VAR RETAIN area (1kB) from time to time and after reset or power on, the data should be restored from %RB area and VAR RETAIN area to %MB area.

The following example uses the function SysMemCpy in library SysLibMem.lib (it is always loaded as default) to copy and restore certain amount of data.

Note

The following example is one method to realize the function of retained %MB area. It retains all 2kB %MB area. Please define the necessary retain memory size for your project. You should take your own responsibility to integrate and test such a method in your project. Usage on your own risk!

  1. Set the Start PERSISTENT %RB0.x and End PERSISTENT %RB0.x area in PLC configuration.

  2. Define an array (as a global variable) which is located in VAR RETAIN area.

  3. Create a program CopyMB to copy data from %MB area to %RB area and VAR RETAIN area.

  4. Create the Function Block according to the screenshot beyond.

  5. Create a program RestoreMB to restore data from the %RB area and VAR RETAIN area to %MB area.

  6. Create the Function Block according to the screenshot beyond.

    Note

    You can change the start and end of the %RB area and adapt the array size in VAR RETAIN area for your own needs. The input dwCount (the number of bytes to be copied) of SysMemCpy should be adapted accordingly.

  7. Insert the RestoreMB at the beginning and CopyMB at the end of the existing program.