LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting modbus hex-data from one register into float

Solved!
Go to solution

Hello,

i am using the modbus-protocol to read an analog-value from a module.

The webpanel of the module displays the hex-value and the float-value. The modbus-function only returns the hex-value.

09FD is 0.780

 

How can i convert the returned hex-value in float?

 

 

There is also a modbus-funtion for this:

public static float GetSingle(ushort highOrderValue, ushort lowOrderValue)

 

But i tried all kinds of using it without luck. (It works, but it does not return the correct value)

 

Thanks for help

 

0 Kudos
Message 1 of 18
(6,399 Views)

Part of the manual of your device should state how to convert the sent value into your decimal value.

 

Just a pure guess, but I would say that you likely just need to multiply by 0.0003 or something close to that.


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 18
(6,383 Views)

Modbus devices tend to have use one of two methods to represent real numbers:

 

  1. Multiply them by N and write the resulting value into a register. This is what Crossrulz was suggesting.
  2. Using the standard IEEE-754 floating point representation. This is usually single precision, which requires 32 bits, so it will usually be in two registers (which is what you can see in the GetSingle function you showed). You then take the two register, join their values and cast to a SGL. Your example only appears to have a single register, so either it's incomplete or this isn't the method that's used or they use half-precision floats, which LV doesn't support. If that's the case, you might need a DLL to do the conversion.

___________________
Try to take over the world!
0 Kudos
Message 3 of 18
(6,371 Views)

I only have one register (see attachment).

But my 4 digit hex-value can be also 32bits. I tried all kind of kombinations  but non of then created the float-values

0 Kudos
Message 4 of 18
(6,361 Views)

What device are you using?  There has to be something in the manual about how to do the conversion.


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 5 of 18
(6,352 Views)

It is called ET-7017 from icp-das.

 

 

0 Kudos
Message 6 of 18
(6,349 Views)

OnlyOne,

 

What range is this AI set for?  +/-10V ?

0 Kudos
Message 7 of 18
(6,333 Views)

yes,

in 10V-range i get 09FD = 0.78

in 5V-range i get 13FB = 0.78

in 1V-range i get 63EA = 0.78

 

 

 

0 Kudos
Message 8 of 18
(6,329 Views)

OnlyOne,

 

Here a are a couple of ways to convert/scale output when range is +/-10V.

Message 9 of 18
(6,322 Views)

Perfect. Works.

Thx a lot

0 Kudos
Message 10 of 18
(6,315 Views)