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

Function Block with Variable Number of Inputs

bvanbata
2007-05-17
2007-06-27
  • bvanbata - 2007-05-17

    Can anyone tell me how I can create a function block that has a variable number of inputs? For example, in the online documentation for V2.3 it says:

    'Insert' 'Input of box' in CFC

    Shortcut: <ctrl> + </ctrl>

    This command is used to insert an input at a box. The number of inputs > is variable for many operators (e.g. ADD can have two or more inputs).

    To increase the number of inputs for such an operator by one, the box > itself must be selected

    Is it possible for me to create a function in my own library that has the same type of functionality, where the user can select the number of inputs?

     
  • shooter - 2007-06-15

    No impossible as the compiler looks at how many inputs are used.

    There is a work around it.

    when using AND for example

    You can make your own functionblock with many inputs and the unused ones fill with true.

    result:=inp1 and inp2 and inp3 etc.

    you must declare all inputs

    inp2:bool:=true; will not work.

     
  • robkristiaan - 2007-06-27

    You can create a functionblock with "variable" amount of input by using an array and an index number

    FUNCTION_BLOCK VarInput
    VAR_INPUT
    Β  Β awInput:ARRAY[0..255] OF WORD; (*255 free asignable inputs*)
    Β  Β byAmount:BYTE; (*for use in a for loop to know when to stop, for example*)
    END_VAR
    
     

Log in to post a comment.