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

    Function block - variable number of inputs

    Scheduled Pinned Locked Moved Mervis
    function block
    2 Posts 2 Posters 692 Views 1 Watching
    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

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post