Generic Variables and FDB

rmarco
2026-06-29
2026-07-22
  • rmarco - 2026-06-29

    Hello everyone,

    I am running into a highly frustrating issue in the FBD editor regarding a Function Block with generic constants (VAR_GENERIC CONSTANT).

    I created a FB using ST, with a generic var, useful for having a variable sized array, as follows:

    FUNCTION_BLOCK Coil
    VAR_GENERIC CONSTANT
        maxEvents: USINT := 5;
    END_VAR
    VAR
        events: ARRAY[0..maxEvents-1] OF IEvent;
    END_VAR
    

    These FBs have also several methods. I declare them as follows in code:

    VAR
        coil1: CDL.Coil<(maxEvents:=1)>;
    END_VAR
    

    and when using them in ST, I have no problems. However, when trying to use them in FDB, I do not know how to do that, as some strange misalignment happens.

    Here's what happens:
    When I add the block to my FBD canvas and assign coil1 as the instance name, the compiler throws this error:
    'coil1' is not an instance of 'CDL.Coil<(maxEvents:=1)>'.

    Same occurs when I try to instantiate blocks such as 'coil1.turnOn' or similar.

    Here is what I have already tried, none of which worked:
    - Deleting the <(maxEvents:=1)> parameter from the text inside the FBD box.
    - Deleting the block entirely, dropping an "Empty Box", and typing coil1 above it to let the IDE auto-complete and format the block.
    - Running a full "Clean All" and rebuilding the code.

    I am aware that I could bypass the graphical editor by calling it in Structured Text. However, I need to keep this logic compatible to FBD.

    Has anyone encountered this specific FBD parsing bug with generic variables?

    Thanks in advance for any insights.

    Best regards,
    Marco

     
  • tvm - 2026-07-22

    I also ran into this, try using Coil<1> as the type in the FBD box. From what I understand, with VAR_GENERIC CONSTANT, the compiler creates separate data types for each different function block declaration.

     

Log in to post a comment.