Codesys function help

stockee
2020-05-02
2020-05-02
  • stockee - 2020-05-02

    Hi,
    I need help with a project of mine.
    I have a function witch look like this :

    code
    

    It basically contains 3 array for different data type,
    and the last_pos array correspond to the last value added or remove in corresponding data arrays

    Then i want a make multiple function witch can have impact on those array : example-
    1- insert data
    2- delete data
    3- search for data

    So i begin with a function that impact 1 of the array ( int) that can insert data in the array

    The function code look like that :

    code
    

    So now.. i need help trying to make these function malleable for all the arrays in my struct : stdata_list
    Basically being able to insert data in whatever list i need.
    I'd wanna have something clean without have 3 set of copy paste code in my function.

    Thanks everyone !

     
  • stockee - 2020-05-02

    code section1:

    TYPE stdata_list :
    STRUCT
        ilast_pos   :   ARRAY[0..2] OF INT;//the position of the last record in the list
        idata           :   ARRAY[GVL.ZERO..GVL.MAX] OF INT;
        sdata           :   ARRAY[GVL.ZERO..GVL.MAX] OF STRING;
        stdata      :   ARRAY[GVL.ZERO..GVL.MAX] OF stitems;
    END_STRUCT
    END_TYPE
    

    code section2:

    FUNCTION finsert : int
    VAR_IN_OUT
        stlist  :   stdata_list;
    END_VAR
    VAR_INPUT
        idata   :   INT;
    END_VAR
    
    
    IF stlist.ilast_pos +1 < GVL.MAX THEN   
        stlist.idata[stlist.ilast_pos +1] := idata;
        stlist.ilast_pos:=stlist.ilast_pos+1;
    END_IF
    
     

    Last edit: stockee 2020-05-02

Log in to post a comment.