GET_NAMED_MEMORY_RETAIN block

At present, the GET_NAMED_MEMORY_RETAIN block is analogous to the GET_NAMED_MEMORY block but GET_NAMED_MEMORY_RETAIN returns the reference to a different memory area than GET_NAMED_MEMORY  (see "Example with reference to different memory area").

The GET_NAMED_MEMORY_RETAIN block returns the →reference to a →retentive memory area the name of which is entered at input NAME. Use the SAVE_ALL_NAMED_MEMORY_RETAIN block or SAVE_NAMED_MEMORY_RETAIN block in order to save all retentive memory areas or just one to persistent storage.
By default, the appropriate file is saved to the subdirectory PLC of the Neuron RTS max installation directory. If you prefer that a different directory is used, contact your system integrator and ask to change the configuration of the system service.

Short summary

Name

GET_NAMED_MEMORY_RETAIN

→POU type

→function

Category

IEC-block, MemoryEnh, block with internal error diagnostic

Conform to →IEC-standard

(plus) not defined in IEC-standard

Graphical interface

Available since

  • version 1.53.0 (for Neuron Power Engineer) and version 3.0.8 or 2.3.1801 of Neuron RTS max
    (warning) This block is supported for the built-in PLC only.

  • version 1.109.0 (for Neuron Power Engineer) and version 3.19.0 of Neuron RTS max: returns the reference to the same memory area as GET_NAMED_MEMORY
    (warning) This block is supported for the built-in PLC and the platforms WindowsX86 and LinuxX86 only.

  • version 3.2.2 (for library Standard) – enhancement: wider interface; returns the reference to a different memory area than GET_NAMED_MEMORY

Example with reference to different memory area

The following example contains 2 program instances: one is writing a configuration value into a retentive named memory area, the other is reading it:

CONFIGURATION LocalConfiguration
  RESOURCE local ON BuiltInPlc { ON_CHANNEL := LocalChannel }
    TASK DefaultTask(INTERVAL := TIME#500ms, PRIORITY := 38229);
    PROGRAM ProgramInstance1 WITH DefaultTask :
      Program1;
    PROGRAM ProgramInstance2 WITH DefaultTask :
      Program2;
  END_RESOURCE
END_CONFIGURATION

As Program2 erroneously uses GET_NAMED_MEMORY() to request the named memory area, the returned reference is not as expected:

PROGRAM Program1
  VAR
    ReferenceToInteger : REF_TO INT;
  END_VAR
 
  ReferenceToInteger := GET_NAMED_MEMORY_RETAIN('IntegerBlock');
  IF ReferenceToInteger <> NULL THEN
    ReferenceToInteger^ := 42;
  END_IF;
END_PROGRAM
 
PROGRAM Program2
  VAR
    ReferenceToInteger : REF_TO INT;
  END_VAR
    
  ReferenceToInteger := GET_NAMED_MEMORY('IntegerBlock');
  IF ReferenceToInteger <> NULL THEN
    /* The following assertion will fail since 'Program2' erroneously requested
     * a named memory block that is NOT retained, thus gets a different block
     * than 'Program1'. For this reason, the value stored in the block is not '42' as
     * expected, but the initial value of zero...
    */
  Assert(ReferenceToInteger^ = 42);
  END_IF;
END_PROGRAM

To fix this issue, you need to replace the call GET_NAMED_MEMORY() by the call GET_NAMED_MEMORY_RETAIN().