[SOLVED] Function with additional outputs

  • ViggoTW

    ViggoTW - 2017-10-17

    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


    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?

  • 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

    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 *)
       bIn1 : BOOL;
       bIn2 : BOOL;
       bOut1 : BOOL;
       bOut2 : BOOL;
    (* 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

    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.