invalid value from function call

travlytle
2016-05-26
2016-06-01
  • travlytle - 2016-05-26

    I've created a function for linear interpolation and depending on how I call it either works or doesn't. Using the shorter method of function call doesn't work. I'm using Codesys 3.5 SP8 Patch 4.

    interp_in := 7;

    // function call - linear interpolation
    lin_interp( x0:= 0, x1:= 100, y0:= 0, y1:= 50, in:= interp_in, out=> interp_out0 );

    // function call - linear interpolation (same as above, different format)
    interp_out1 := lin_interp( 0, 100, 0, 100, interp_in ); //this format is not working correctly, I don't know why

    IMG: 2016

     
  • yannickasselin1 - 2016-05-27

    Are you sure it is a function?

    It seems to be a function block, which is different.

    Try this:

    lin_interp( 0, 100, 0, 100, interp_in );
    interp_out1 := lin_interp.out;

    This should work if it is a function block.

     
  • travlytle - 2016-05-27

    This doesn't work: interp_out1 := lin_interp.out;

    It doesn't like the .out

    It says 'out' is no input of 'lin_interp'

    The function in the tree menu shows, lin_interp (FUN). This would be a function or not necessarily?

     
  • Anonymous - 2016-05-28

    Originally created by: scott_cunningham

    If you only have one output for the function, don't define it as a var out.

    Don't:

    FUNCTION MyFunction
    VAR_INPUT
    Β  Β VarIn : BOOL;
    Β  Β Var2 : INT;
    END_VAR
    VAR_OUTPUT
    Β  Β Out1 : BOOL;
    END_VAR
    Out1 := VarIn;
    

    Do:

    FUNCTION MyFunction : BOOL
    VAR_INPUT
    Β  Β VarIn : BOOL;
    Β  Β Var2 : INT;
    END_VAR
    MyFunction := VarIn
    

    Now you can call it in the way you want:

    Answer := MyFunction(TRUE, 27);
    

    If you define one or more VAR_OUTPUTs, then you have to use the full notation so the compiler knows which output you want.

     
  • travlytle - 2016-06-01

    This worked thanks!

    I changed the function by removing the out var, and setting the function name := (equation).

    And then updated the code to:

    // function call - linear interpolation
    interp_out0 := lin_interp( x0:= 0, x1:= 100, y0:= 0, y1:= 50, in:= interp_in);

    // function call - linear interpolation (same as above, different format)
    interp_out1 := lin_interp( 0, 100, 0, 100, interp_in );

    I believe I found the old method in the help file too, not so helpful!

     

Log in to post a comment.