LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

hex string conversion to ascii string conversion

I am trying to interface with an embedded system that sends responses in hex valued strings.  However, all of the Labview vi's that manipulate strings assume ASCII strings.  Is there a way to convert my hex valued strings to ASCII strings so I can parse, compare, etc using Labview.  As an example, the embedded will send a response consisting of a hex valued string such as "5B8102004A3FFEFF5D" most of which has no meaning in ASCII code.  Even worse, the "5B" and "5D" characters are of course the "[" and "]" symbols in ASCII, so this really confused the Labview VI's.

 

Thanks for any ideas or help.

0 Kudos
Message 1 of 7
(3,889 Views)

As you said, the hex values have no meaning as ASCII so I don't understand your desire to convert to that. What is the data actually supposed to represent?

 

There are numerous methods to deal with hex data and they have often been discussed. You can use the String to Byte Array, the Type Cast, the Unflatten From Stringe, etc. The Unflatten From String has an input that allows you to select byte order (endianess) and that might be something you need.

0 Kudos
Message 2 of 7
(3,874 Views)

How do you break up the hex string?  Are the first two characters supposed to represent an 8 bit integer?  Or maybe the first 4 characters represent a 16 bit integer?  Or what?  All of these characters are ASCII characters.  They also happen to be within the Hex character set.  It is how they are supposed to be manipulated that will determine how to code this situation. 

 

There is no such thing as converting a Hex character to an ASCII character.  All characters are ASCII.  Some are decimal characters, some are hex characters, others are just plain characters.  But they all are ASCII.

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 7
(3,865 Views)

I think this is what he wants...  I used this for converting data received from a camera that was in string format representing a hex value...  If not, this should help point you in the right direction.

0 Kudos
Message 4 of 7
(3,853 Views)

Steve:  With your vi, a response of 5B converts to a hex string of 5B.  What purpose does this serve?  Also, you are using I8.  5BFC converts to 5B.  I don't think this will do the trick.  The OP's input string is already in hex.

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 7
(3,844 Views)

oops, sorry, that part was used to strip off unwanted characters from the return string...

0 Kudos
Message 6 of 7
(3,837 Views)

 


@horatioinc wrote:

I am trying to interface with an embedded system that sends responses in hex valued strings.  However, all of the Labview vi's that manipulate strings assume ASCII strings.  Is there a way to convert my hex valued strings to ASCII strings so I can parse, compare, etc using Labview.  As an example, the embedded will send a response consisting of a hex valued string such as "5B8102004A3FFEFF5D" most of which has no meaning in ASCII code.  Even worse, the "5B" and "5D" characters are of course the "[" and "]" symbols in ASCII, so this really confused the Labview VI's.


 

A string is a string is a string in LabVIEW. There is no inherent distinction between ASCII or binary. Some values are control characters in ASCII that cannot be displayed as characters, but that does not mean they are not real.

 

All string operations work fine using generic binary strings. We don't discriminate on the basis of certain arrangements of the eight bits, all 256 possibilities are equally legitimate. The string VIs don't assume a certain subset of characters. You just need to do it right (e.g. don't randomly mix hexadecimal formatted strings with binary strings with the display set to hexadecimal and assume they are equivalent).

 

This is not rocket science. We need to know what you have, what operations you are trying to do, and what the desired result should be.

 

Please create a small VI that contains the raw string input as a diagram constant and let us know what you need to do with it.

0 Kudos
Message 7 of 7
(3,827 Views)