Any data type

tzygmunt
2019-03-20
2019-03-21
  • tzygmunt - 2019-03-20

    I would like to create a function block that can use multiple data types and constants. For example I would like to be able to pass in int, dint, uint, udint data types.

    I can do this using the 'any' data type in my Var_input of the function block. The only problem is that it will not let me pass in a constant to the function block (see attachment).

    There must be a way to do multi data_type/constant parameters. The Move function block accepts multiple datatypes and constants. How does the Move do this?

    Any Data_type.pdf [44.68 KiB]

     
  • dFx

    dFx - 2019-03-21

    Constants are part of your compiled code, while variables are memory address. I think this is why you can't use any for constants.
    Move is a value change operation, meaning it expects a value at the in parameter, and a memory address at the out one.
    Btw, I have no clue how it handles the input declaration.

     
  • tzygmunt - 2019-03-21

    I found a work around that should work for my application.

    If I have the input parameter as a LReal CODESYS will automatically type cast from any number or constant to LReal without loss of data.

    I define my destination parameter as type 'Any', and cast the result into the destination data type.

    This seems to work with the testing that I have done at this time.

    An example of this running with multiple data types is attached.

    TestFunction.pdf [14.95 KiB]

     

Log in to post a comment.