Does anyone know how to convert an ascii string to the real value? I am taking a hex buffer (42,14,8F,5C) and converting to its ascii equivalent using oscat_basic.BUFFER_TO_STRING. I am now stuck on how to convert this value in its real value (37.140) to display on HMI. Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you are starting with IEE754 (a codesys REAL type) then you could use "SomeString := TO_STRING(UrRealVal);" Probably it would be better to put "UrRealVal" into a TextVariable field and a format (i.i. %2.3f) in the Text field of a viosualization element.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Does anyone know how to convert an ascii string to the real value? I am taking a hex buffer (42,14,8F,5C) and converting to its ascii equivalent using oscat_basic.BUFFER_TO_STRING. I am now stuck on how to convert this value in its real value (37.140) to display on HMI. Thanks.
that's the bit pattern for an iee754 floating point number, not a string.
And it's 3.714 not 37.14
If you are starting with IEE754 (a codesys REAL type) then you could use "SomeString := TO_STRING(UrRealVal);" Probably it would be better to put "UrRealVal" into a TextVariable field and a format (i.i. %2.3f) in the Text field of a viosualization element.
a hint how formatted "printing" of reals in strings is possible:
https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#904a