07-12-2018 01:17 PM - edited 07-12-2018 01:20 PM
Curious about something. I'm using Modbus and Ethernet IP. Getting some data from a mass flow meter and the code that uses the typecast is working as expected. The code using the convert to SGL does not work. Why? I thought all I was doing was taking two U16 integers, swapping them upper-lower then converting to single precision float. What am I missing?
Solved! Go to Solution.
07-12-2018 01:28 PM
@PaulG. wrote:
The code using the convert to SGL does not work. Why?
Are you referring to the SGL bullet? If so, that just takes the number and changes it to a SGL format. But the value will be the same (ex: U16 100 -> SGL 100). You typically have to do some math the the Modbus values in order to get the floating point value you want.
07-12-2018 01:31 PM
Hi Paul,
"typecasting" is something different than "converting"…
Typecasting is NOT changing the underlying data (aka those 4 bytes of your 2 U16 values), it is only changing the way those bytes are interpreted. (In your case from array of U16 to SGL.) So their memory representation is the same, but their (interpreted) value is different.
Conversion is changing the underlying data: an U32 value of 0x0000.0001 (an integer value of 1) is converted to 0x3F80.0000, when you convert it to a SGL value of 1: the (interpreted) value of both data items is the same, but their representation in RAM is different.