Function in Codesys and the wrong return value

alex
2021-03-16
2021-03-17
  • alex - 2021-03-16

    Hello guys, have a very weird issue and cant help but ask.
    I created the Function with very simple math in it adding two REALS

    Function always returns zero, same code works great with FB but not in a function.

    POU Function added to application, and then to Mast task under cyclic program.

    FUNCTION DIVME : REAL
    VAR_INPUT
    num01:REAL;
    num02:REAL;
    END_VAR
    VAR
    END_VAR


    DIVME := (num01+num02);

    When i call this function from the program the result will always be zero regardless of the value of two input parameters. Please guide me to solution

     
  • i-campbell

    i-campbell - 2021-03-16

    Is Supplemental being called?

     
    • alex - 2021-03-16

      Yes Supplemental is one of the two tasks under MAST.
      Like mentioned before code worked ok in Function Block but not in a function..

       
  • ojz0r - 2021-03-17

    What happens if you write:

    result := (num01+num02);
    

    ?

     
  • alex - 2021-03-17

    Miracle happens ojz0r, indeed it fixes stuff immediately and provides a warm and fuzzy feeling.
    Thank you much guys for help,, Resolved.

     

Log in to post a comment.