LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help converting a string (containing hex bytes) to a decimal number

I have been working on writing a driver for a device my company makes.  We currently are in the process of switching over to Labview and I was tasked with writing the first one.  As such I'm pretty inexperienced with the program (few days).
 
I am having one problem.  I can not get the numeric display to correctly convert the hexadecimal string into its base 10 equivalent.  For instance, I send the command C9 <hex> to the device and get the response 00FA <hex> back after removing the echo, device confirmation, and correctly reordering the bytes (Device sends low the high and need to reverse).  However, the hexadecimal string to number converter says this equals 0 when it should read 250.
 
Any help is GREATLY appreciated!


Message Edited by Moya on 07-17-2008 05:01 PM
0 Kudos
Message 1 of 5
(2,945 Views)
While I look at your VI, go ahead and check out the following thread:
____
Ryan R.
R&D
0 Kudos
Message 2 of 5
(2,939 Views)
The problem is that the string you get from the VISA Read contains bytes that are encoded for their numeric ASCII value rather than text characters.  If your string was literally "00FA" the Hex Number to String function you had would work.  However, your string is actually two bytes (I think) where the first byte has an ASCII value of 00 and the second has a value of FA = 250.  In that case, the string is the "flattened" representation of a 16-bit number.  For that we use the Typecast function to get the number.

See attached, modified VI...

Dan Press
PrimeTest Automation
Message 3 of 5
(2,936 Views)

One thing I might add to Dan's solution:

The numeric indicator is a signed integer, so keep that in mind if you return hex values that give negative numbers. 🙂

____
Ryan R.
R&D
0 Kudos
Message 4 of 5
(2,931 Views)
Awesome! Thank you very much for your help!
0 Kudos
Message 5 of 5
(2,900 Views)