LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Hex String To Float

Solved!
Go to solution

Hello, I have a device which I am trying to communicate with using UDP. The device returns the data in Hex strings but I don't have very good documentation on the format of these strings. Here is what I do have:

 

00 - Command type / BYTE

01 - Response Code / BYTE

02 - Task ID / BYTE

03 - Channel / BYTE

04-07 - PS Current / Float

08-11 - PS Current Aux / Float

12-15 - DAC Voltage / Float

16-19 - PS Current ripple / Float

20-23 - PS Ground Current / Float

24-27 - Temperature / Float

28-31 - PS Volts / Float

32-35 - Spare channel volts / Float

 A sample data return might look like this:

 

c8:00:10:00:7f:8d:f1:ba:ff:ed:22:39:f8:ff:1f:41:4c:41:52:39:ff:57:63:38:3d:f1:a7:42:ff:35:be:39:7f:49:a7:3a

 

The value I really care about right now is the PS current in Byte 04 - 07. So I did an offset of 4 and a lenght of 4 on string subset which would return something like 7f8d f1ba. But I have not had success turning this in to an actual number using the Hexadecimal to number VI trying every possible representation.

 

Does anyone have any idea how I can convert this? I added a screenshot of what I have now. Thank you in advance for any help.

 

On edit, in case this is helpful a current of 1.00005 would return 96:01:80:3f or the full response incase I have the offsets wrong:

 

c8:00:1f:00:96:01:80:3f:ff:57:63:38:c2:00:80:3f:ef:8c:ed:3a:ff:57:02:38:0a:25:c8:42:34:e3:7f:3e:bf:4f:88:ba

 

Message Edited by Pawel Kowalski on 02-15-2010 02:07 PM
0 Kudos
Message 1 of 10
(8,906 Views)
Solution
Accepted by topic author Pawel_Kowalski

Note: I am assuming you put in the colons for readability, and that you are not actually getting that from the UDP.

 

What you are actually getting is a string of bytes, not a string of characters representing hex values. In other words, you are not getting the character 'F' to indicate a hex value of F. You are getting a byte of value decimal 15. Additionally, the characters are in reverse order. To convert it you have to chop off the section you want, reverse the string, and then use the Type Cast function:

 

Message Edited by smercurio_fc on 02-15-2010 02:28 PM
Message Edited by smercurio_fc on 02-15-2010 02:28 PM
Message 2 of 10
(8,890 Views)
Works perfectly, thank you vert much.
0 Kudos
Message 3 of 10
(8,884 Views)

The Unflatten From String will also work.

 

Message Edited by Dennis Knutson on 02-15-2010 01:47 PM
Message 4 of 10
(8,876 Views)

String to Hex ERROR.jpg

Hi all.

I did the first example but I received another answer.

 

Where is  error ?

Best regards

Iskander

 

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

What is the reprsentation for the constant wired into the typecast?

 

If you look at S-Mercurio's solution, you can see it is a Single Precision Float.

 

I bet you wired in a double precision constant.

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

Thanks

 Yes, I use S-Mercurio's solution.

I wired a double precision constant.

I didn't receive correct answer " 1,00005" 

Regards

0 Kudos
Message 7 of 10
(7,696 Views)

Most likely the problem is the representation on the string, not on the numeric - in the original example, the display style is almost definitely in hex. In the new one, it's not. Iskander, make the display style on the string visible, change it to hex and then type in the text again and it should probably work.


___________________
Try to take over the world!
0 Kudos
Message 8 of 10
(7,674 Views)

@Iskander wrote:

Thanks

 Yes, I use S-Mercurio's solution.

I wired a double precision constant.

I didn't receive correct answer " 1,00005" 

Regards


I'm confused by your message.

 

So if you did wire a double precision constant, and did not get the correct answer of 1.00005,

then I can only assume you went back and fixed it with the single precision constant?  And did you get the correct answer then?

0 Kudos
Message 9 of 10
(7,670 Views)

Thanks all for the attention and help

I changed "const" to control and do "Hex".

All work.

Best regards.

0 Kudos
Message 10 of 10
(7,617 Views)