Read real values in a .txt files with SysFileRead: possible?

2013-01-25
2013-01-30
  • fredleemans - 2013-01-25

    Hello,

    I try to read "Real values" from a .txt files (~5000 parameters), directly on the Flash card of my Rexroth PLC. I can open it with SysFileOpen and I can read value from it with SysFileRead but, i received information in Byte... So in place to have 20 different positions, I have data in Byte, so maybe an array of 100 bytes...

    Is it possible to read directly the different real positions and store it in a array of real?

    Thank you for your help,

    Bests regards,

    Fred

    IMG: test.PNG

     
  • shooter - 2013-01-26

    what about STRING_TO_REAL

     
  • fredleemans - 2013-01-29

    Hello,

    In fact, the SysFileRead, take the byte value of every digit. For example in .csv file: the value to read is -0,013, first line. I will have finally in my "buffer":

    and then '$R' and '$N' for Return and New line.

    After I transform the byte in ascii with a IL_Byte_to_Ascii (something like that, I don't remember the right name). Present in Library of codesys.

    Then you use a CONCAT for several digit (used '$R' and '$N' to stop concat). In the end you have a string with the value '-0,013'. You can use now the conversion string_to_real in order to have the real value.

    PAY ATTENTION that with a ',' (comma) the conversion string_to_real will not work, you MUST have '.' (point).

    '-0.013' will give -0.013 in the real value.

    Until now I didn't find something faster to read a real in a . csv or .txt...

    Regards,

     
  • shooter - 2013-01-29

    the comma and the dot are language dependent, i would follow the english version, easier as you can not change the comma in a CDF.
    have a look into the oscat library.

     
  • ilie.c.lucian - 2013-01-30

    You can also try this.
    A real number has 32bits in Codesys. So you can try the following:

    1. Read your real number, using SysFileRead, into a variable declared in the memory (eg. %MD8200), in double word (DWORD) format.

    2. Declare a real variable at the same marker address (eg. %MD8200) and you have got your real number.

    Example:

    BufferDWord AT %MD8200:DWORD;
    BufferReal AT %MD8200:REAL;

    BufferDWord=SysFileRead(...);
    YourRealNumber=BufferReal;

    Regards,
    Lucian

     

Log in to post a comment.