Variable Type detection?

  • Anonymous - 2019-02-16

    Originally created by: fk5

    Can CoDeSys do conditional variable type identification?

    I have a scale function that takes in a REAL value and scales it to some new range, then outputs a REAL. But, sometimes I’m trying to scale an INT, or a DINT, or a BYTE or SINT, etc. how can I make this function automatically recognize the input type, do a xxx_TO_REAL, run my scale function, then do a REAL_TO_xxx, then output the result as an xxx instead of a REAL?

    Any solution besides “make a different function for each variable type” would be awesome.


  • WAGOKurt

    WAGOKurt - 2019-02-20

    In this case I would use; INT_TO_REAL(your_var) or WORD_TO_REAL(your_var) etc.

  • Anonymous - 2019-02-21

    Originally created by: scott_cunningham

    Codesys V3 now supports the ANY_TYPE, which would work, but I don’t believe this is available on Codesys V2.3.

  • Anonymous - 2019-11-05

    Originally created by: fk5

    So, it works this way for using different inputs. That's good.
    But, I also want it to output into the same type as whatever is connected.
    Is this possible? (Example: I'd like to modify this function to work regardless if dd is a REAL, INT, BYTE, ...)

    FUNCTION anyTestFunction : REAL
    in1: REAL := ANY_TO_REAL(in1);
    in2: REAL := ANY_TO_REAL(in2);
    in3: REAL := ANY_TO_REAL(in3);

    anyTestFunction := in1 + in2 + in3;

    aa: INT := 2;
    bb: REAL := 2.1;
    cc: BYTE := 3;
    dd: REAL;

    dd := anyTestFunction(aa, bb, cc);

    IMG: any_num_01.png

  • Anonymous - 2019-11-12

    Originally created by: scott_cunningham

    You could return the ANY type, but then you would have to determine which type within the ANY type.

  • shooter

    shooter - 2019-11-26

    i do it by paralleling inputs and outputs in ver 2 so input is real and int same as output.


Log in to post a comment.