LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting array of Double Precision values to U16 for MODBUS

Hello,

 

I am trying to send over pressure and temperature information via the Input Register array in MODBUS TCP.  My question is, how to I properly send over an array of double precision values without loosing my data?

 

For example, my array of data looks like:

 

12.0001

32.001

0.00051234

0.0014838

1.02

12.0232

31.920

 

Thanks so much.

0 Kudos
Message 1 of 10
(7,342 Views)

@huskyblacktools wrote:

Hello,

 

I am trying to send over pressure and temperature information via the Input Register array in MODBUS TCP.  My question is, how to I properly send over an array of double precision values without loosing my data?

 

For example, my array of data looks like:

 

12.0001

32.001

0.00051234

0.0014838

1.02

12.0232

31.920

 

Thanks so much.


We need more information.

 

Double precision means 8 bytes of data.  A single register is only 16 bits or 2 bytes of data.  Many times, machines that need floating point data will use 2 consecutive registers, (4 bytes) but that means only single precision floating point data.

 

You show 7 pieces of data there.  How many registers are you trying to write it to?

0 Kudos
Message 2 of 10
(7,338 Views)

Thank you Ravens Fan for replying.

 

I missed one extra point of data.  Below is what I'd like to send:

 

12.0001

32.001

0.00051234

0.0014838

1.02

12.0232

31.920

2046

 

The array above is an array of double precision values.  I will convert that array to an array of single precision floating data to reduce data size.

 

Since I have eight pieces of single precision floating point data now, I will need to write to 16 registers correct?  What is the best method to split up each piece of data into two consecutive registers?

 

Attached is a Slave Send Data.VI that I want to send this data through.  The end goal is to have a Master PC (not using labview, but a MODBUS utility) to read my MODBUS TCP message from the "Slave Send Data.vi" 

 

Thanks

 

0 Kudos
Message 3 of 10
(7,335 Views)

You can use coerce to force the double float to become a single.  Then use typecast to convert that to a U16 array.

 

There are other functions in the Numeric, Data Manipulation palette that may be useful such as swap bytes, swap words, flatten/unflatten to string, and split/join numbers.  Because one thing you might have to do is worry about Endianism on your numbers.

 

 

Message 4 of 10
(7,333 Views)

Ravens Fan, I think this will work!  Tomorrow I'll test it on the equipment and report back.  I've been following many MODBUS threads you've posted in since starting my project and your advice has been great.  Thank you for your assistance.

 

 

0 Kudos
Message 5 of 10
(7,328 Views)

Worked great!  Thanks Ravens Fan

0 Kudos
Message 6 of 10
(7,303 Views)