Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Retain variables from File, cmpApp

alex87
2014-11-28
2014-11-28
  • alex87 - 2014-11-28

    Hello,

    I'm trying to implement retrieving Retain variables from File, using lib cmpApp. I found a sample in Codesys Store:
    http://store.codesys.com/application-manager.html

    So I copied PRG into my project added lib and retain variable, And I get an error that RTS_IEC_RESULT is unknown type, but is declared like:

    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 := 'App1.ret';
       pApp         : POINTER TO APPLICATION;
       Result                : RTS_IEC_RESULT; (* Result code *)
       xInit         : BOOL;
    END_VAR
    

    Code:

    (* The retain variables are stores in a file and get retrieved afterwards. *)
    IF NOT xInit 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);
          xInit := TRUE;
          (* 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);
          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.*)
    Result := AppRestoreRetainsFromFile(pApp, sFileName);
    

    I have no Idea how to declare it other way??? Any Ideas?

    regards,
    Alex

    IMG: RTS_IEC_RESULT.png

     
  • TimvH

    TimvH - 2014-11-28

    With newer library versions it is required (and also better for older versions) to use the namespace to define which RTS_IEC_RESULT you want to use.

    In this case you need to define the variable as:
    Result : CmpApp.RTS_IEC_RESULT;

     
  • alex87 - 2014-11-28

    Thank you TimvH didn't know that, Build OK, now testing.

    regards,
    Alex

     

Log in to post a comment.