Passing an I/O Array to a Function or Function Block

jtobias
2015-05-04
2015-05-07
  • jtobias - 2015-05-04

    Hello Guys,

    I was trying to convert my version 1 to version 2. I was trying to pass an array of I/O ports to my function block but, it didn't work.

    Any help really appreciated.

    Regards,

    John

    ( Version 1, works )

    PROGRAM PLC_PRG
    VAR
    TAFB : Test_Array_FB;
    END_VAR

    TAFB(IO_port1 => P1_Order1_Led, IO_port2 => P1_Order2_Led, IO_por3t => P1_Order3_Led, IO_port4 => P1_Order4_Led, IO_por5t => P1_Order5_Led);


    FUNCTION_BLOCK Test_Array_FB
    VAR_INPUT
    END_VAR
    VAR_OUTPUT
    IO_port1: BOOL;
    IO_port2: BOOL;
    IO_port3: BOOL;
    IO_port4: BOOL;
    IO_port5: BOOL;
    END_VAR
    VAR
    END_VAR

    IO_port1 := TRUE;
    IO_port2 := TRUE;
    IO_port3 := TRUE;
    IO_port4 := TRUE;
    IO_port5 := TRUE;


    ( VERSION 2, Passing an array to a function block )

    FUNCTION_BLOCK Test_Array_FB
    VAR_INPUT
    END_VAR
    VAR_OUTPUT
    IO_port : ARRAY [0..4] OF BOOL;
    END_VAR
    VAR
    Ctr : INT;
    END_VAR

    FOR Ctr := 0 TO 4 BY 1 DO
    IO_port[Ctr] := TRUE;
    END_FOR

    PROGRAM PLC_PRG
    VAR
    IO : ARRAY [0..4] OF BOOL;
    TAFB : Test_Array_FB;
    END_VAR

    IO[0] := P1_Order1_Led;
    IO[1] := P1_Order2_Led;
    IO[2] := P1_Order3_Led;
    IO[3] := P1_Order4_Led;
    IO[4] := P1_Order5_Led;

    TAFB(IO_port => IO);

     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3

  • TimvH

    TimvH - 2015-05-07

    Shouldn't it be:

    TAFB(IO_port => IO);

    ( Write IO to outputs )
    P1_Order1_Led := IO[0];
    P1_Order2_Led := IO[1];
    P1_Order3_Led := IO[2];
    P1_Order4_Led := IO[3];
    P1_Order5_Led := IO[4];

     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3


Log in to post a comment.