Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

decoding hex IEEE-standard 32 bit binary float

Hi, After reading many discussion forums on this topic, I still have some problems deciphering the following code.
 
I am reading from a serial port data. The data consista of 6 floating numbers IEEE-standard 32-bit binary float
Each value is 4 bytes and is transferred with LSB first and MSB last.
 

Example: (hex values)

 

10 02 00 01 28 00 35 69 D9 42 EC 9E 4A 3C E7 28 10 10 3E 55 23 1F 3E 1E 88 1D 3F 71 72 C0 3E 22 10 03

 

first there are some control characters, namely (10= DLE, 02=STX 00=receiver address 01=transmitter address 28=message type 00=shaft number). From there onwards till '22' (checksum) are 6 numbers:

 

35 69 D9 42
EC 9E 4A 3C
E7 28 10 10 3E  (two times 10 as 'character stuffing' since it means DLE and should not be read as a control character)
55 23 1F 3E 1E
88 1D 3F 71
72 C0 3E

 

This first three characters can be decoded as following (following the manual of the sensor):

 

108.70542          (shaft rpm)

0.012367            (torque in kNm)

0.14078              (power in kW)

 

However, I can't seem to translate the abovementioned hex numbers into the right 'normal' decimal values. I tried using the hex string to number or typecast it, but apparently I am doning something wrong...

 

Any idea how to translate the hex numbers correctly?

 

many thanks,

 

Thijs

 

0 Kudos
Message 1 of 3
(4,096 Views)
Hi

first of all you are not having hex data but binary data, hex is a way to display binary data.
second you should use a typecast to a 4byte double  for those four bytes
as a last point the order in a hex 32 bit number display is  back to front.

taken your example  35 69 D9 42
you should type in a hex display of a 32 bit number control 4269D942 th result after typecasting to a single is 108.705  this looks correct.

for the program see the attached vi in lv7.1.1

I also added a conversion from a string of 4 characters (first building this from a byte array of 4 numbers) and hopla it works
greetings from the Netherlands
Message 2 of 3
(4,092 Views)

Many thanks!

Sometimes a solution can be so simple!

Thijs

0 Kudos
Message 3 of 3
(4,088 Views)