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

Function block method default arguments

2023-12-21
2024-01-04
  • sean-barton - 2023-12-21

    I have default arguments specified for function block methods but when calling a method, an error is produced requiring me to supply all the arguments despite there being default values.

    According to the online documentation, under section "Calling a Method" and subsection "argument passing" of the following link:
    https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_obj_method.html

    "Passing an argument for an input ... can be omitted ... for which a default or initial value was specified in the declaration..."

    I have found this to be the case for all Codesys IDEs I've used, 3.5.11, 3.5.16, 3.5.17, 3.5.19.

    Am I missing something?

     
  • SiegeLion - 2023-12-22

    It's not that you missed something, it's that CODESYS doesn't have this feature. I hope CODESYS can add this feature.

    We also hope to add function overload functionality.

     
  • tvm - 2024-01-04

    This works for me in Schneider Machine Expert 2.2, which is based on Codesys 3.5.19.
    It did not work in Machine Expert 2.1, which was based on Codesys 3.5.16.

    METHOD PUBLIC Method1 : INT
    VAR_INPUT
        TestVar:            INT:= 5;
    END_VAR
    
    Method1:= TestVar;
    
    PROGRAM SR_Main
    VAR
        TestFB:         TEST_FB;
        Var1:           INT;
    END_VAR
    
    Var1:= TestFB.Method1();
    
     
  • joanm - 2024-01-04

    The new TwinCAT 4026 will add those default parameters, as TwinCAT drinks from Codesys I guess that will be implemented soon (or maybe, it already is given what tvm says in the previous post).

     

Log in to post a comment.