Help w Function design: Can Codesys use optional parameters?

ectech
2012-04-02
2012-06-11
  • ectech - 2012-04-02

    Hello to all, I'm a newbie to Codesys and I am wondering how to configure a custom Function, so some of it's parameters are optional; meaning that when one calls the Function not all parameters need to be assigned a value of their same type. I configured a custom Function Block to do a task, and it works great, but I am interested in configuring the same code as a Function since I don't need output(s) to do these tasks. I'm working with a Wago 871 PLC I am not sure if Function Blocks are a good way to continue coding, since multiple instances will be created and called as my programs become larger and more complex.

    I can choose which parameters of a Function block instance to use, but not of a Function, however from what I have read in these posts it seems that Functions can be more of a memory saver for limited memory PLC's, especially if one wants to configure a lot of code+visualizations in the device (space is premium). Is it possible to send something like a NULL value to an input parameter? Or, is there a way that the parameter (in my case an ARRAY of Bool) can be "set" as optional, or as a "generic" type, so one can pass it a place holder of some sort just to continue with the rest of the Function's code?

    Thanks in advanced,

    Maro

     
  • spfeif - 2012-06-11

    I understand what you are saying but where would the need be in a PLC to call it optional? You can create your interface for the worst case scenario and assuming the FB is backwards compatible just pass data that is set to defaults of the variable types. All inputs must be assign in CoDesys. Outputs do not. If you do not assign anything to a standard input then on each call the input is set to the initialization default of the variable type typically FALSE and 0. If you have an INPUT_OUTPUT type then you can not compile / errors unless you assign a variable to the input that has both read/write access.

    They sort of have optional inputs in V3. You can hide inputs to a FB and it will not complain at compile time (like in V2.3 when it shows ??? and compiler errors will state that FB xxxxx requires x amount of inputs. So in V3 if your interface of the POU changes (say you add soemthing) and you use the interface when the FB is loaded the new input is hidden.

    Why would you use a program over a Function block.
    a program is a singleton. You can not create instances and is only in one place in PLC memory which allows the retaining of variable through each program call. It can also be assigned to PLC tasks.

    a FB acts the similar to a program but for each instance a separate place in memory is created. You can not assign a FB to a task.

    Since I can never tell the internal/compiler benefits between the two I basically use the logic that if this POU never needs to have instances then I make it a program. If it is something that is acting like a Class and requires instances then there is only one choice a FB.

     

Log in to post a comment.