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

Multiple Data Types for FB's Inputs/Outputs

jethridge
2015-06-23
2015-06-24
  • jethridge - 2015-06-23

    Is it possible to have an input determine what the datatype will be for the remaining inputs/outputs? Example, if input1 is 0, then input2 and input3 are REAL, if input1 is 1, then input2 and input3 are DINT, etc. I haven't found anything that says you can (or can't) use conditional statements when defining your variables.

     
  • shooter - 2015-06-23

    well yes and no
    as any variable has a declaration, the answer is NO, however, it depends on how you are using it.
    you are allowed to have 2 variables pointing to one marker, like rin1 at MW6 and Iin1 also AT MW6.
    you can also use pointers for this (i try not to use them as they are not in IEC61131 and are processor dependent.)

    Why would you need this in the first place, when you explain it, probably the answer is a lot easier, give us an example.

     
  • jethridge - 2015-06-24

    Writing a filter AOI (I've looked through the OSCAT library, and none fit what we are looking for) and want to use it for INT, REAL and possibly TIME. I'd like to have an input named "Selector" and it be a byte. If "Selector" is 0, then it defines other inputs/outputs as INT, if "Selector" is 1, then it defines them as REAL, etc. I've tried writing conditional statements in the declarations, but I don't think it's possible. It'll be easy enough to copy/paste the AOI three times and change the data types, but having the dynamic data types on the variables would've been cool.

     
  • shooter - 2015-06-24

    as you can imagine it is impossible to have a change in datatypes in any program or function or block.
    however mixing them is possible, done it before.

    In a function block make 3 or more inputs, for each type 1
    VAR_INPUT
    iIN:INT:=0;
    rIN:real:=0;
    tIN:Time:=0;
    end_var

    in the block:
    riIn:=INT_TO_REAL(iIN); ( conversion of the input)
    rtIN:=TIME_TO_REAL(tIN);
    filterin:=ADD(riIN,rIN,rtIN);( all others will be 0)

    another way is to use a structure with above types in them.
    so you can use any of the types with the same varname.

    like varname.rin
    varname.iin

    You only need 2 types of filter 1 type with DINT
    and one for LREAL.

    btw a good filter is always working with reals.
    I have made a fuzzy filter to get rid of values that were not in the band needed.

     

Log in to post a comment.