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

[2D ARRAY] [FB]

damian177
2021-07-02
2021-07-03
  • damian177

    damian177 - 2021-07-02

    Hi,
    I have this two dimensional array in main POU:

    checked_options : ARRAY[1..200, 1..3] OF BOOL := [200(0),3(0)];

    How can I send to my function block only one row from my array (in FB i would like to 1D ARRAY)in short notation ? checked_options[1,1] , checked_options[1,2] and checked_options[1,3] ....

     
  • damian177

    damian177 - 2021-07-02

    My FB:

    FUNCTION_BLOCK my_fb
    
    VAR_INPUT
        pNumberChecked: POINTER TO BOOL;
    END_VAR
    

    In POU:

    VAR
    checked_options : ARRAY[0..199, 0..2] OF BOOL := [200(0),3(0)]; 
    my_fb : my_fb1;
    END_VAR
    
    my_fb1 (pNumberChecked:= ADR(checked_options[0, .. ]) );
    

    Is posssible in this way assign only one row to my FB instance ?

     
  • Fless

    Fless - 2021-07-02

    you could use the alternative syntax ARRAY OF ARRAY
    FB:

    FUNCTION_BLOCK my_fb
    
    VAR_INPUT
        pNumberChecked: POINTER TO ARRAY[0..2] OF BOOL;
    END_VAR
    

    POU:

    VAR
    checked_options : ARRAY [0..199] OF ARRAY [0..2] OF BOOL := [200([3(FALSE)])];
    my_fb : my_fb1;
    END_VAR
    
    my_fb1 (pNumberChecked:= ADR(checked_options[0]) );
    
     
  • damian177

    damian177 - 2021-07-03

    I can't change 2D ARRAY. They are a data form SCADA. Too much work.
    What do you think about below solution ?

    FB:

    FUNCTION_BLOCK my_fb
    
    VAR_INPUT
        pNumberChecked: POINTER TO ARRAY[0..2] OF BOOL;
    END_VAR
    

    POU:

    VAR
    checked_options : ARRAY[0..199, 0..2] OF BOOL := [200(0),3(0)];
    my_fb : my_fb1;
    END_VAR
    

    For example, one of row (25) transfer to FB :

    my_fb1 (pNumberChecked:= ADR(checked_options[25,0]))
    

    will it work ?

     
  • damian177

    damian177 - 2021-07-03

    My soultion:
    POU: (one of them row) 27 for example:

    my_fb1 (pNumberChecked:= ADR(checked_options[27,0 ]) ); 
    

    FB:

    VAR_INPUT
        pNumberChecked:  POINTER TO BOOL;
    END_VAR
    
    VAR
             ii: BYTE:=0;
        phone_Nr_checked:ARRAY[0..2] OF BOOL ;
    END_VAR
    
    
    FOR ii := 0 TO 2 BY 1 DO
        phone_Nr_checked[ii] := pNumberChecked[ii];
    END_FOR;
    
     

Log in to post a comment.