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

Issue calling methods in CFC

JTG
2020-01-07
2023-11-10
  • JTG - 2020-01-07

    This is a bug report of sorts, as well as a way for me to leave a note for others who may encounter this issue.

    Calling a method in a CFC is pretty straightforward when that method belongs to another function block, but it doesn't work very well when the method belongs

    If the internal method has input variables, the compiler will give a C0040 error "Function 'MethodName' requires exactly '#' inputs", even when the input pins are all visible and connected.

    I've found 2 workarounds,

    1. Don't use inputs, just call local variables directly from the method. This gets clunky really fast so isn't a great solution if you need inputs. Also, the method's box will just be floating in the CFC with no visible connections, which kinda defeats the purpose of CFC

    2. Give the method a return type or an output. For whatever reason, this avoids the compile error. You never have to write to the output or use it in the CFC, but if you hide the output pin the error will return so you have to just leave it dangling or connect it to something

    Hopefully these workarounds won't always be necessary in the future

    IMG: Bild

     
    πŸ‘
    1
  • ohm-625 - 2022-03-23

    Thanks,
    I faced the same issue and I would have lost much more time without your thread.
    It's not limited to CFC.

    Regards,

     

Log in to post a comment.