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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
what about STRING_TO_REAL
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,
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.
You can also try this.
A real number has 32bits in Codesys. So you can try the following:
Read your real number, using SysFileRead, into a variable declared in the memory (eg. %MD8200), in double word (DWORD) format.
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