CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Sat Feb 24, 2018 8:54 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 42 posts ]  Go to page Previous 1 2 3 Next
Author Message
PostPosted: Wed Nov 19, 2014 6:17 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2511
Hello,

this 'manual retain save issue' will be solved with 3.5SP6,
there is a workaround available:
Execute a 'sync' by
Quote:
Sys ExecuteCommand
after saving the retains manually.
This lead to a file flush.. retains are saved immediately.

This will be not needed then with 3.5SP6 release.

BR
Edwin


Top
   
PostPosted: Mon Nov 24, 2014 11:06 pm 
Offline

Joined: Wed Feb 27, 2008 7:35 pm
Posts: 8
Hi,

can you help me my code don't work:

Code:
IF Save THEN
   
   (* First delete the retain file.
      This is necessary, because the function AppStoreRetainsInFile appends the data at the end of the file. *)
   fbDelete(xExecute:=TRUE, sFileName:=sFileName);
   IF fbDelete.xDone OR (fbDelete.xError AND fbDelete.eError = File.Error.NOT_EXIST) THEN
      (* Attention: It takes at least one cycle until xDone is TRUE *)
      fbDelete(xExecute:=FALSE);
      Save := FALSE;
      (* Now, it's the time to save the retains. *)
      pApp := AppGetCurrent(pResult:=ADR(Result));
      IF pApp <> 0 THEN
         (* Store the variables in a file*)
         Result := AppStoreRetainsInFile(pApp,sFileName);
         _(pszCommand:='sync');
         
      END_IF
   END_IF
END_IF

(* Restore the Retain Variables from the file.
   For storing and restoring, the same pointer to application (pApp) must be used.*)
IF Restore THEN
   Result := AppRestoreRetainsFromFile(pApp, sFileName);
   Restore := FALSE;
END_IF



I can restore the retain, after a power fail.


Top
   
PostPosted: Wed Nov 26, 2014 11:12 am 
Offline

Joined: Fri Apr 18, 2014 5:36 pm
Posts: 69
Hi,

It is working in my case:
Code:
PROGRAM AppRetain
VAR
   fbDelete            : FILE.Delete; (* Function block to delete the file *)
    (* The retain file <application-name>.ret is placed in the directory of the bootproject *)
   sFileName           : STRING := 'App10.ret';
   pApp            : POINTER TO APPLICATION;
   Result              : RTS_IEC_RESULT; (* Result code *)
   Result1             : RTS_IEC_RESULT; (* Result code *)
   xInit            : BOOL;
END_VAR

Code:
IF NOT xInit THEN
   pApp := AppGetCurrent(pResult:=ADR(Result));
   xInit := TRUE;
END_IF

IF xSavePers THEN   
   (* First delete the retain file.
      This is necessary, because the function AppStoreRetainsInFile appends the data at the end of the file. *)
   fbDelete(xExecute:=TRUE, sFileName:=sFileName);
   IF fbDelete.xDone OR (fbDelete.xError AND fbDelete.eError = File.Error.NOT_EXIST) THEN
      (* Attention: It takes at least one cycle until xDone is TRUE *)
      fbDelete(xExecute:=FALSE);
      xSavePers := FALSE;
      (* Now, it's the time to save the retains. *)
      IF pApp <> 0 THEN
         (* Store the variables in a file*)
         Result := AppStoreRetainsInFile(pApp,sFileName);
         SysProcess._('sync',ADR(Result1));
      END_IF
   END_IF
END_IF

(* Restore the Retain Variables from the file.
   For storing and restoring, the same pointer to application (pApp) must be used.*)
IF bRestore THEN
   Result := AppRestoreRetainsFromFile(pApp, sFileName);
   PersVarsChk := PersVars;
   bRestore := FALSE;
END_IF


And you should add "sync" command in CODESYSControl.cfg, like described here:
viewtopic.php?f=21&t=5714

Best regards,
Zdenko.


Top
   
PostPosted: Thu Nov 27, 2014 3:17 pm 
Offline

Joined: Wed Feb 27, 2008 7:35 pm
Posts: 8
Hi thanks...but after this stop the Raspi...wen i will restore the RETAIN


Top
   
PostPosted: Fri Nov 28, 2014 9:44 am 
Offline

Joined: Fri Apr 18, 2014 5:36 pm
Posts: 69
Hi,

I configured xSavePers and bRestore control bits as Global variables, so I can save and restore Retain variables from the application.

Restore is made in the INIT phase and Save is done after Retain variables value change.

Best regards,
Zdenko.


Top
   
PostPosted: Fri Dec 12, 2014 1:44 pm 
Offline

Joined: Wed Apr 30, 2014 2:02 pm
Posts: 3
My small code for autosave retain on change with time filter (no raspberry!, another platform). As is.

+ CmpChecksum.lib

Code:
PROGRAM RetainManager
VAR_INPUT
   RetainFilePathName : STRING := '/tmp/extend/pccard/SD_MMC0_1/Retain';
   SaveFilterTime : TIME := T#5S;
   ForceSave : BOOL;
END_VAR
VAR
   Init: BOOL;
   pRetainFilePathName : POINTER TO STRING;
   pCurrentApp : POINTER TO APPLICATION;
   RetainAreaSize: __XWORD;
   pRetainArea: POINTER TO BYTE;
   dwCRCSave: DWORD;
   dwCRC: DWORD;
   TOF1 : TOF := (PT := SaveFilterTime);
   R_TRIG1: R_TRIG;
END_VAR
VAR_OUTPUT
   RTSIECResult : RTS_IEC_RESULT;   
   AttemptSaveCounter: INT;
END_VAR

IF NOT Init THEN
   pCurrentApp := AppGetCurrent(ADR(RTSIECResult));
   IF RTSIECResult<>0 THEN RETURN; END_IF
   RetainAreaSize := AppGetAreaSize(pApp:= pCurrentApp, uiType:= DA_RETAIN, pResult:= ADR(RTSIECResult));
   IF RTSIECResult<>0 THEN RETURN; END_IF
   pRetainArea := AppGetAreaAddress(pApp:= pCurrentApp, uiType:= DA_RETAIN, pResult:= ADR(RTSIECResult));
   IF RTSIECResult<>0 THEN RETURN; END_IF
   IF LEN(RetainFilePathName) <> 0 THEN
      pRetainFilePathName := ADR(RetainFilePathName);
   ELSE
      pRetainFilePathName := ADR(pCurrentApp^.szName);   
   END_IF
   RTSIECResult := AppRestoreRetainsFromFile(pCurrentApp, pRetainFilePathName^);   
   CASE RTSIECResult OF
      0: // #define ERR_OK 0x0000
      16#1E: // #define ERR_SIGNATURE_MISMATCH 0x001E   /* Signature mismatch of an api function */
      16#32: // #define ERR_FILE_ERROR 0x0032   /* File error. e.g. cannot open a file for writing because it could be write protected */
   ELSE RETURN;
   END_CASE
   dwCRCSave := CRC32Finish(ulCRC:= CRC32Update(ulCRC:= CRC32Init(), pData:= pRetainArea, ulSize:= RetainAreaSize));
   Init := TRUE;   
END_IF

R_TRIG1(CLK := ForceSave);

dwCRC := CRC32Finish(ulCRC:= CRC32Update(ulCRC:= CRC32Init(), pData:= pRetainArea, ulSize:= RetainAreaSize));

IF dwCRC <> dwCRCSave OR R_TRIG1.Q THEN
   IF NOT TOF1.Q OR R_TRIG1.Q THEN
      RTSIECResult := AppStoreRetainsInFile(pCurrentApp, pRetainFilePathName^); // записасать в файл
      IF RTSIECResult = 0 THEN
         dwCRCSave := dwCRC;         
      END_IF
      AttemptSaveCounter := AttemptSaveCounter + 1;
      TOF1(IN := TRUE);
   END_IF
END_IF

IF TOF1.Q THEN
   TOF1(IN := FALSE);
END_IF


Top
   
PostPosted: Fri Nov 20, 2015 8:13 pm 
Offline

Joined: Mon Feb 16, 2015 1:56 pm
Posts: 9
Edwin Schwellinger wrote:

This will be not needed then with 3.5SP6 release.



Hello Edwin.
What does it mean?
I tried retains in 3.5sp7 and it still doesn't work.


Top
   
PostPosted: Sat Nov 21, 2015 12:07 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2511
Hi,
usually nothing is needed except an UPS... no additional code to execute.

BR
Edwin


Top
   
PostPosted: Sat Nov 21, 2015 12:33 pm 
Offline

Joined: Mon Feb 16, 2015 1:56 pm
Posts: 9
So the problem with manual saving retains to sd card isn't solved?
And the only way to have retains saved without additional code is unterruptable power supply?


Top
   
PostPosted: Thu Dec 24, 2015 9:02 am 
Offline
User avatar

Joined: Wed Apr 08, 2015 11:06 am
Posts: 36
Hi everyone! Has anyone used 24C32(64) EEPROM chip to saving retain variables? Is it possible? I have this part: http://www.ebay.com/itm/400503978923


Top
   
PostPosted: Wed Apr 13, 2016 11:08 am 
Offline

Joined: Mon Feb 16, 2015 1:56 pm
Posts: 9
Edwin Schwellinger wrote:
Execute a 'sync' by
Quote:
Sys ExecuteCommand
after saving the retains manually.
This lead to a file flush.. retains are saved immediately.


Hello. I tried
Code:
Sys*Process*Execute*Command*('sudo sync', ADR(cmdResult));

but it doesn't save retains.
Code:
Sys*Process*Execute*Command*('sudo reboot -h now', ADR(cmdResult));

Reboot do the job.
Is there a command to save retains without rebooting?


Top
   
PostPosted: Sat Jun 18, 2016 1:21 pm 
Offline

Joined: Sun Feb 21, 2016 7:57 pm
Posts: 38
Edwin Schwellinger wrote:
Hi,
usually nothing is needed except an UPS... no additional code to execute.

BR
Edwin


Hello! You can learn how to turn off the raspberries to remain variable retain? Linux any team for this need. Thank you!


Top
   
PostPosted: Sat Jan 07, 2017 1:30 pm 
Offline

Joined: Tue Nov 04, 2014 3:45 pm
Posts: 12
kruglovay wrote:
Is there a command to save retains without rebooting?


Im also looking ;-) I tried "sudo sync" with no sucess


Top
   
PostPosted: Sat Jan 07, 2017 9:45 pm 
Offline

Joined: Thu Apr 23, 2015 4:51 pm
Posts: 31
Is there persistent variables on codesys 3?

Sent from my SM-N9005 using Tapatalk


Top
   
PostPosted: Sun Jan 08, 2017 6:44 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2511
Hi,

in general there are retains, but you need a graceful shutdown under Linux Debian.
(no Switch off the power supply withour shutdown)
-> so UPS (uninterrupted power supply ) is mandatory to have retain variables.

BR
Edwin


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 42 posts ]  Go to page Previous 1 2 3 Next

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited