Unexpected output from REAL_TO_STRING

kmpm
2014-09-02
2015-01-07
  • kmpm

    kmpm - 2014-09-02

    Hi,
    I am using REAL_TO_STRING to convert some decimal numbers to be transmitted as ascii over a serial connection.
    Everything works fine unless the value to be converted is <1 and >-1.

    While using CODESYS Control Win V3 and CODESYS for Raspberry PI I get things like.
    REAL = "STRING"
    0.7 = "0.7"
    -0.5 = "-0.5"

    But with a Berghof EC1000 I get the following
    0.7 = "7.0e-1"
    -0.5 = "-5.0e-1"

    This represents the correct values but was completely unexpected by the receiving end.
    Bigger and equal to 1 and lower or equal to -1 works as expected.

    I am not able to find any documentation on how REAL_TO_STRING is supposed to work
    and I'm now wondering if there is any standard for how this is supposed to be done?
    If the implementation is allowed to differ then I will need to make my own function to deal
    with it. I might have to do it anyway since I can't trust the implementation being consistent.

    Does anyone know how it's supposed to work and/or have similar experience from other vendor/hardware implementations?

    Thanks in advance
    Peter

     
  • kmpm

    kmpm - 2015-01-07

    I'm bumping this issue and also adding a request.
    If you have some different Hardware could you please test the following.

    PROGRAM PLC_PRG
    VAR
    Β  Β rValue: REAL;
    Β  Β sValue: STRING;
    Β  Β bIsOk: BOOL;
    END_VAR
    rValue := 0.2;
    sValue := REAL_TO_STRING(rValue);
    bIsOk := sValue = '0.2';
    

    And then report back the make and model of the plc, perhaps runtime version if you know it and if you got TRUE in bIsOk or not.
    The Berghof EC1000 returns FALSE because the string is '2.0e-1'.
    CODESYS Control Win V3 returns TRUE.

    This would give me some hints on how common this issues is.

     

Log in to post a comment.