LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why typecast works but convert to does not

Solved!
Go to solution

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? 

 

 

 

PaulG.

LabVIEW versions 5.0 - 2023

“All programmers are optimists”
― Frederick P. Brooks Jr.
0 Kudos
Message 1 of 3
(2,411 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 3
(2,403 Views)
Solution
Accepted by topic author PaulG.

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.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 3
(2,402 Views)