Creating control program

2022-07-12
2022-07-12
  • aivarasutkus - 2022-07-12

    Hi.
    Im working with ABB AC500 series in Automation Builder V2.5. How do you implement function or function block in codesys with user data structure as a parameter. I was working with siemens TIA portal and there you have Data blocks and in functions called IN/OUT type where you can both read, process and write back variables. Or you do this in other way in this software? I was thinking about creating my User data type and store objects in global variables table.
    Thanks.

     
  • fajean - 2022-07-12

    You are looking for ways to pass arguments by reference rather than value.

    Google "CODESYS VAR_IN_OUT".

    You can also define VAR_INPUT variables in functions blocks and functions that are of type "REFERENCE TO X", where "X" is the type you want to pass by reference. Since you are passing a reference, it does not matter that it is defined as an input, you will be able to act on the "thing" that is passed as a reference, not on a copy. I do everything in structured text and do not use VAR_INPUT to visually connect function blocks in diagrams, and that is what I use for everything, for reasons that I have forgotten about, probably because there were hassles from the compiler with VAR_IN_OUT.

    Reference assignment requires the "REF=" operator, because the normal assignment operator does a memory copy with references.

    You can also use pointers (POINTER TO X). This is (to me) less clean, but they work as you would expect pointers to work, in a few cases they work where references do not. Copying a pointer to another pointer uses the normal assignment operator, because pointers are addresses. Dereferencing a pointer uses the "^" operator (e.g. "my_struct^.member_variable := 1).

    All of the above work with function blocks and structures.

     

Log in to post a comment.