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
(6,455 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
(6,451 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
(6,448 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
(6,446 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
(6,441 Views)

Worked great!  Thanks Ravens Fan

0 Kudos
Message 6 of 10
(6,416 Views)

Hi everyone,

 

Sorry to reopen this post again, but I have a similar question.

I tried to use the Ravens' method, but it didn't work for me. I receive U16 data, but I can't convert appropriately. I attached a print screen, what I have and what I need to find.

 

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

It would have helped if you attached your VI so I can see your attempt.

 

But the issue is that the register values need to be swapped before they are typecast to Single.

See below to see two different ways of doing it.

 

Your front panel picture  doesn't show all the U16 registers, but you can see from the first 6 registers how it got to the first 3 values in your results.

 

Message 8 of 10
(3,632 Views)

Hi RavensFan,

 

Your solution worked, but I lost some values. The machine which we are monitoring, send to us 29 values (sensors from temperature and pressure)

My VI is attached for you verify (before your solution).

 

Thank you so much for your attention.

0 Kudos
Message 9 of 10
(3,586 Views)

You need to use Swap Words,  not Swap Bytes.  Note that mine shows "16" on the function while yours show "8".

 

You are grabbing 29 registers.  That means 14 and a half "pairs" of registers when you combine them into 32 bit integers.

If you are trying to grab 29 single precison floats, then you need to wire in 58 so that 58 registers get paired into 29 single precision floats.

 

You wanted single precision floats, so you still need to do that typecast.

 

Pro Tip:  Delete your 300 constant from the wait function.  Then right click on the input and use Create Constant.  Now you'll have the right datatype and will get rid of that red coercion dot.

Message 10 of 10
(3,580 Views)