LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extra \00 in HX string to ASCII conversion

I am working on a project to convert HEX values to ASCII. Instead of getting in over my head, I figured I'd play and get myself familiar with Hex conversions. I googled "hex to ascii labview" and I came to the link below to get me started:

 

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YGwnCAG&l=en-US

 

I've done exactly what it states in the web document, but when type a letter (I've used the letter L) & run the VI, I keep getting three \00 in the ASCII output when I turn on Codes display. Is this normal behavior? I'm working in LabView 2012.

0 Kudos
Message 1 of 9
(9,417 Views)

It is because you are converting to an I32, which uses 4 bytes.  Therefore the output must be 4 bytes in length.  The \00 just means that those bytes have a value of 0 (NULL).

 

Maybe you should describe a little better exactly what you are trying to do.  Where do the characters come from?  Why convert to ASCII?  I have a feeling we can simplify your life by quite a bit if we had that information.


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 9
(9,410 Views)

Well, looking at the documentation (starts on page 36), I THINK it's hexadecimal. I'm now having second thoughts.

 

I apologize, this is my first dip into this kinda stuff. I am used to serial commands, but nothing like this so I apologize for my ignorance.

0 Kudos
Message 3 of 9
(9,392 Views)

All you get is a binary string with 10 bytes. Use string to byte array and then index out all the desired values. You can create a lookup table to translate each value into the huma readable meaning as listed in the manual.

 

If you request a measurement, you get 5 bytes back, but this is already formatted in decimal. No conversion needed, just trim the x00 termination character.

0 Kudos
Message 4 of 9
(9,384 Views)

Something like this? Also, where are you getting the 10 bytes from? And the 5?

0 Kudos
Message 5 of 9
(9,311 Views)

@Eric1977 wrote:

Something like this? Also, where are you getting the 10 bytes from? And the 5?


from the manual you had attached. 😄

 

Note that if you read a value, it is already formatted as a decimal string. Simply take the string subset of the first four bytes or scan into a to DBL if you want it as a numeric type.

0 Kudos
Message 6 of 9
(9,303 Views)

OK, I'll admit, I'm lost. This is the first time doing a hexidecimal conversion. Maybe if I seen a example of what your talking about, the concept(s) might sink in.

0 Kudos
Message 7 of 9
(9,267 Views)

Can you attach some raw sample strings received from the instrument?

0 Kudos
Message 8 of 9
(9,254 Views)

As crossrulz mentioned, only one byte of the "Char" is used. See this example for an explanation and a solution to get rid of the null character:

 

https://forums.ni.com/t5/Example-Code/Using-the-LabVIEW-Key-Down-Event/ta-p/3996186

 

To quote the note in the example:

Capture.JPG

 

-Carl

0 Kudos
Message 9 of 9
(9,040 Views)