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

Using VAR_STAT in FB

fpin
2018-01-09
2018-01-10
  • fpin - 2018-01-09

    Hi everybody,

    I'm founding some problems with the VAR_STAT in the function block: I don't understand why the variables that I declare in the VAR_STAT field are set to 0 everytime that the function block is called. I tried to not initialized the variables but nothing happens, do I have to set something else?

    I saw that if I use the VAR type I obtain the result that I want but why it should be like this?

     
  • Anonymous - 2018-01-09

    Originally created by: rickj

    As I understand VAR variables declared in the main FB body are already static. I'm not sure how VAR_STAT is interpreted in the main body, but it probably ends up being something like a class variable, where it's the one and same variable for all instances of the FB. Try incrementing a VAR_STAT variable on the first execution of the block to see if it counts the number of instances.

    I believe that if you use VAR_STAT in a method or a function then you would get the expected behavior.

     
  • fpin - 2018-01-10

    rickj hat geschrieben:
    As I understand VAR variables declared in the main FB body are already static. I'm not sure how VAR_STAT is interpreted in the main body, but it probably ends up being something like a class variable, where it's the one and same variable for all instances of the FB. Try incrementing a VAR_STAT variable on the first execution of the block to see if it counts the number of instances.
    I believe that if you use VAR_STAT in a method or a function then you would get the expected behavior.

    Ok, thanks for the answer. I will try to increment a VAR_STAT variable when I will have time to do that test.

     

Log in to post a comment.