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 in function block

tvm
2019-10-07
2021-02-02
  • tvm - 2019-10-07

    According to the help file "If you declare a local variable in a function block as RETAIN, CODESYS stores the complete instance of this function block in the Retain range (all data of the function block); however, only the declared RETAIN variable is treated as such." (https://help.codesys.com/api-content/2/ ... ersistent/)

    I created a function block with only the following variables:

    VAR
    Β  Β Test1:Β  Β ARRAY[1..50] OF UINT;Β  Β //100 bytes
    END_VAR
    VAR RETAIN
    Β  Β Test2:Β  Β ARRAY[1..50] OF DINT;Β  Β //200 bytes
    END_VAR
    

    I have a program that only implements one instance of this function block. Using SIZEOF at runtime shows a function block size of 312 bytes

    Now, if I right click on the device, and go to "Device Memory Info", the size of my Retain Data is only 203 bytes.

    If the complete instance of the function block is stored in the retain range, I would expect the retain data size to be the same as the function block size (312 bytes), but it isn't, it's only 203 bytes--the size of the retain data. Is the manual incorrect?

    I am using Schneider M241 PLC with Machine Expert 1.1, which is using Codesys 3.5 SP12

    thanks

    Tim

     
  • dawidr - 2021-02-02

    That is the question I'm also looking answer for!
    Anyone has more info?

     

Log in to post a comment.