cancel
Showing results for 
Search instead for 
Did you mean: 

How to transform 32-bit FLOAT number to 16-bit UNSIGNED

SOLVED
zde92
Member
Solved!

How to transform 32-bit FLOAT number to 16-bit UNSIGNED

Hi there,

 

I am trying to write 32-bit single precision number to two 16-bit unsigned modbus regsiters. Any ideas how could that be done? 

 

thanks in advance!

6 REPLIES 6
cbutcher
Trusted Enthusiast

Re: How to transform 32-bit FLOAT number to 16-bit UNSIGNED

How much precision do you need, and how do you want to use the value later?


GCentral
GerdW
Knight of NI
Solution

Re: How to transform 32-bit FLOAT number to 16-bit UNSIGNED

Message contains an image

Hallo zde,

 

maybe this is an inspiration to you:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
cbutcher
Trusted Enthusiast

Re: How to transform 32-bit FLOAT number to 16-bit UNSIGNED

Message contains an image

splitJoinSgl.png

I got this far, but yours is much nicer. I didn't realise before looking into this how miserable single-precision is...


GCentral
zde92
Member

Re: How to transform 32-bit FLOAT number to 16-bit UNSIGNED

For now, I don't have specific requirement for precision. I'am trying to do the modbus master/slave simulator. The SGL value will be written in input register of slave, then read with Read from input registers function on master. Since the modbus functions accepts the U16 format, the conversion is needed. 

zde92
Member

Re: How to transform 32-bit FLOAT number to 16-bit UNSIGNED

Message contains an attachment

Hi there, I tried something similar using type cast to transform to U32 and the used Split Number. But probably, I would need to create the opposite conversion on master where I read the values from register? 

 

 

 

GerdW
Knight of NI

Re: How to transform 32-bit FLOAT number to 16-bit UNSIGNED

Hi zde,

 

I tried something similar using type cast to transform to U32 and the used Split Number.

So you get the same result using more functions!? Smiley Very Happy

 

But probably, I would need to create the opposite conversion on master where I read the values from register? 

Yes, when you want to "simulate" this master too…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019