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

Data conversion INT to UDINt (double)

beamster
2017-01-30
2017-01-30
  • beamster - 2017-01-30

    Hello,

    I'm a n00b to Codesys programming, so sorry in advance if my question is a bit stupid
    This is probably not a dedicated V3-question, but since I'm working in V3.5 SP10 I guess I should post my question here anyway?!

    I work with a Seeeduino CAN-Bus shield mounted on Arduino (sender) and a Opus A3 Display (receiver). Im sending INT values of max value of 65365 (2 bytes) with CAN to the display. Like an example: Im sending INT x =12345 to the display and give it to a global variable global_x(INT) and show it on the display. This works.

    But now I want to convert this integer to a double. I think in CodeSys you need to use UDINT? Because I want to display 123,45 (12345/100). I tried to give the value of global_x to a local variable (UDINT) and divide by 100. But this is not working when I want to show it on my display.

    Maybe someone has a clue? Or is there a way to convert an INT to a UDINT (double) in Codesys when you declare a local variable?? Or do I have to give UDINT to my global_x also ?

    With kind regards,

    beamster

     
  • Anonymous - 2017-01-30

    Originally created by: Massimo.Milluzzo

    The function you are looking for is INT_TO_UDINT.

    Another way to visualize the value 123,45 from an integer is to set, as text variable displayed, the code

    INT_TO_REAL(yourVariable)/100
    

    The conversion to REAL is required in order to "enable" the decimal values.

     

Log in to post a comment.