Breadcrumbs

AppRetainHandling

The recommended retain handling in the CODESYS application is described here. 

There are two ways in which the retain variables are stored in the KCH Control. 



InSRAM: 

Here the retain variables are mapped directly into the SRAM. 

The prerequisite is that an SRAM module is present and that the SRAM is configured in the web configuration. 


Powerfail: 

Here the retain variables are stored in a file on the Device. 

If there is no SRAM module or if the SRAM was not configured in the web configuration, the powerfail mode is automatically used. 


The loading of the retain variables is executed automatically when the boot project is loaded. 

If no retain file exists, an error is triggered. 


Saving the retain variables must be executed from the application. 


Beispiel:  

C++
VAR
   Result: CmpApp.RTS_IEC_RESULT;
   pCurrApp: POINTER TO CmpApp.APPLICATION;
   sFileName: STRING;
END_VAR

 pCurrApp := AppGetCurrent(pResult:= Result);
 sFileName := CONCAT(pCurrApp^.szName, '.ret');
 Result := AppStoreRetainsInFile(pApp:= pCurrApp, pszFilName:= sFileName);



Remarks

  • The used retain handling is logged in the Log.