• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Function block - variable number of inputs

    Mervis
    function block
    2
    2
    70
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tmmke last edited by

      Hi,

      I would like to make a function block with a variable number of inputs.
      Like with the standard AND operation for example.

      Does anyone know how I can achieve this?
      It doesn't matter if it has to be in ST of in FBD.

      Kind regards,
      Tom

      1 Reply Last reply Reply Quote 0
      • T
        tomas_hora administrators last edited by

        This is not a standard feature of ST or FBD but there is a small hack to achieve this. See the example below. It only works if the input variable is named "in" (the same works for output variable named "out") and the type is array.

        FUNCTION InDemo : LINT
        VAR
        i : INT;
        END_VAR
        
        VAR_INPUT
            In : ARRAY[0..63] OF BOOL;
        END_VAR
        
        (*function block's body*)
        result := 0;
        FOR i := 0 TO 63 DO
               // nejaky kod
             IF In[i] THEN result := result + 1; END_IF;
        END_FOR;
        
        InDemo := result;
        END_FUNCTION
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post