LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can i convert int16 to float32 (MSW-LSW) ?

Solved!
Go to solution

Can someone please tell me how to convert int16 to float 32 (MSW-LSW)?

Kind regards,
Balázs

0 Kudos
Message 1 of 9
(3,756 Views)

Not sure exactly what you are after here. Did the To SGL not do what you want?  If not, do you have an example to help us understand your issue?


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
0 Kudos
Message 2 of 9
(3,744 Views)

I use the following tool for scanning modbus TCP as reference. I would like to find out how to get 61.06516 which is a float32 (MSW-LSW)

modbus_read.jpg

 

Here is my code:

modbus_.jpg

 

My "Output" is 17096. I reckon this number is the one that should be somehow transformed to 61.06516. Am i right or wrong?

0 Kudos
Message 3 of 9
(3,720 Views)

And this is why examples are so important.

 

Your problem is you need to use 2 words to combine to make your 32-bit value.  Use Array Subset to get words 5 and 6 (index 4 and 5).  Then you can just use Type Cast to convert to a SGL value.


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 4 of 9
(3,712 Views)

Hi,

I get 1,39232E+12 as output when MSB=17012, LSB=17096.

 

Is there something that i am doing wrong?

0 Kudos
Message 5 of 9
(3,640 Views)
Solution
Accepted by topic author LTBALAZS

You want SGL, not DBL (DBL is eight bytes) change the representation of all your orange elements to SGL. (indicator, diagram constant wired to the top of typecast, NAN in the other case)

You cannot turn four bytes into eight.

 

Where did you find this VI?

 

altenbach_0-1601620842999.png

 

 

0 Kudos
Message 6 of 9
(3,631 Views)

I created a numeric indicator then changed its data type to SGL, and the data type of "Casted Number" to SGL (right click -> properties -> data type..)
I found that vi here:
https://forums.ni.com/t5/Example-Code/Cast-Two-I16-Numbers-into-One-Double-Precision-Number-Using/ta...

 

Thanks for your help!

Regards,
Balázs

0 Kudos
Message 7 of 9
(3,613 Views)

Here is a pro tip that was not done in the link you provided, nor on CrossRulz's example above.

 

Make the label visible on that typecast constant and edit it to say SGL.  That documents that the intention is to typecast the input to a Single, and not one of the other 5 data types that are also floating points with an orange color.

0 Kudos
Message 8 of 9
(3,591 Views)

@RavensFan wrote:

Here is a pro tip that was not done in the link you provided, nor on CrossRulz's example above.

 

Make the label visible on that typecast constant and edit it to say SGL.  That documents that the intention is to typecast the input to a Single, and not one of the other 5 data types that are also floating points with an orange color.


That is exactly what I do for constants where it is important to know the data type.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 9
(3,543 Views)