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

[SOLVED] Function with additional outputs

ViggoTW
2017-10-17
2017-11-06
  • ViggoTW - 2017-10-17

    Hi,
    I am used to functions returning only one data type, depending on how the function itself is declared (for example FUNCTION fName : INT, which returns an INT).
    However, I read the follwoing at Beckhoff's webpage in their chapter about functions

    [1]

    I am familiar with this in Function Blocks where you declare your output variables for example inside a VAR_OUTPUT (...) END_VAR, but I am hoping that someone could show me an example of additional outputs in a Function?

     

    Related

    Talk.ru: 1

  • Anonymous - 2017-10-19

    Originally created by: scott_cunningham

    Define the outputs the same way as a function block. You can keep the traditional single output and and the second and third and fourth outputs as var outputs or you can delete the traditional output type and put all outputs as var outs.

     
  • ViggoTW - 2017-11-01

    Trying to add VAR_OUTPUT in a function results in compiler error 3820: " 'VAR_OUTPUT' and 'VAR_IN_OUT' not allowed in functions"

    The code I tried looked as follow

    Declaration:

    (* Declaration *)
    FUNCTION F_fun : BOOL
    VAR_INPUT
    Β  Β bIn1 : BOOL;
    Β  Β bIn2 : BOOL;
    END_VAR
    VAR_OUTPUT
    Β  Β bOut1 : BOOL;
    Β  Β bOut2 : BOOL;
    END_VAR
    VAR
    END_VAR
    (* Code *)
    bOut1 := bIn1;
    bOut2 := NOT bIn2;
    
     
  • Anonymous - 2017-11-01

    Originally created by: scott_cunningham

    Looks like it's a limitation with the version you are running. In version 3, it works. A crude workaround would be to create your function as a program instead and define any local variables as VAR_TEMP so they reset at every call.

     
  • shooter - 2017-11-06

    The link refers to Version 3 Twincat, Here it works, however in 2.3 it is not working, you should have 1 output var returned by a function, however it is still possible to change other outputs within a function.
    It all depends on the type of machine and software.
    and yes you are correct, please use FB for this.

     

Log in to post a comment.