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 logi.RTS 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 |
|
Category |
|
Conform to →IEC-standard |
not defined in IEC-standard |
Graphical interface |
|
Available since |
|
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().