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

Array of FB initialization

2018-02-14
2018-02-15
  • wpmccormick - 2018-02-14

    Trying to figure out how to initialize an array of FB, where the FB itself is initialized with a STRUCT (through the FB_Init).

    This works:

    bar: STRUCT_BAR := (b1:=val1, b2:=val2);
    foo: FB_FOO(bar);
    

    This does not:

    bar1: STRUCT_BAR := (b1:=val1, b2:=val2);
    bar2: STRUCT_BAR := (b1:=val1, b2:=val2);
    foo: ARRAY[1 .. 2] OF FB_FOO[(bar1),(bar2)]; // or like FB_FOO[(bar1,bar2)] and other variations I could think of
    

    The compile error would look something like:
    [ERROR] C0032: Cannot convert type STRUCT_BAR to type POINTER TO FB_FOO

    Thanks!

     
  • wpmccormick - 2018-02-14

    Figured it out ...

    METHOD FB_Init //of FB_FOO
    VAR_INPUT
    Β  Β bInitRetains: BOOL;
    Β  Β bInCopyCode: BOOL;
    Β  Β var: STRUCT_BAR; 
    END_VAR
    foo: ARRAY[1 .. 2] OF FB_FOO[(var:=bar1),(var:=bar2)]; 
    
     
  • josepmariarams - 2018-02-15

    It seems that is not possible to pass diferent parameters to the array fb initialization.

    You can, but, initiqlize internal variables as in structures. ( An fb is an structure too).

    Se the post

    l viewtopic.php?p=16838#p16838 l

    Be healty!

     

Log in to post a comment.