cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

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

Solved!
Go to solution
Highlighted

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!

0 Kudos
Message 1 of 7
(415 Views)

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?

0 Kudos
Message 2 of 7
(411 Views)
Solution
Accepted by topic author zde92
04-21-2017 02:31 AM

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

Hallo zde,

 

maybe this is an inspiration to you:

check.png

Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2017 on Win7+cRIO
Kudos are welcome Smiley Wink

Message 3 of 7
(405 Views)

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

splitJoinSgl.png

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

Message 4 of 7
(399 Views)

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. 

0 Kudos
Message 5 of 7
(384 Views)

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

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? 

 

 

 

0 Kudos
Message 6 of 7
(378 Views)

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
CLAD, using 2009SP1 + LV2011SP1 + LV2017 on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 7 of 7
(370 Views)