LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change streaming hexadecimal bytes to decimal numbers? (Device- Accelerometer)

I have previously posted relevant question regarding the subject in a general term. After studying the communication protocol, I have more specify question to ask. How to I use type cast in labview to convert string of hexadecimal to decimal? How do I properly define type? 

 

The hexadecimal funnels to the typcast contain header byte, information bytes and checksum byte. I need to exclude them from the hexadecimal so I can get a clean decimal result. How do I solve that? I am using Labview 8.5. Please let me know if I should find out more about how to solve the problem. 

 

0 Kudos
Message 1 of 5
(3,738 Views)

Hi Hito88,

 

An example of what you expect the device to produce would help.

 

When you say hexadecimal, what are YOU meaning - diferent people call different things hexadecimal!

 

For example is it a string of ASCII printable text characters in the range 0-9 and A-F, viewable in Hyperterm, or in a string indicator set to Normal display mode. Alternatively, is it in BINARY, so that a (16 bit) integer appears in two bytes from the device and does not (generally) look like an ASCII text hexadecimal string when viewed in Hyperterm.

 

If it's printable ASCII characters, say like "7EED", one way would be to use scan from string, with a format of %nx, where n is the number of characters you expect to see in the string. In this example %4x would get a value of  32493.

 

For now, I'll assume you have a text string like AB7EEDCB, [by which I mean that is what you see in a string indicator, set to normal display mode - sorry to labour the point, but it is really important] where AB is the header, 7EED is the data and CB is the checksum. Scan from string with a format of %2x%4x%2x will give you the three outputs you are looking for, which in my example would be 171, 32493 and 203.

 

Rod.

 

0 Kudos
Message 2 of 5
(3,724 Views)

Hi Rod!

 

The accelerometer would actually produce ASCII. My application gives me a sample labview code that convert ASCII to hexadecimal. I need to modify it to convert ASCII to decimal. I believe it is more convenient to modify the sub VI (which convert ASCII to hexadecimal) by properly define the type in the 'typecast' function, so that there is less chance to mess up the overall code.

 

Does 'scan from string' as you suggested discard the header bytes and checksum bytes? 

Maybe I should add the SubVI for everyone to refer to. I believe I only need to define the type in 'typecast'fucntion.

 

Hito!

 

 



0 Kudos
Message 3 of 5
(3,710 Views)

You need a bit more than that.  Lets see if i'm tracking.

 

You are recieving an ASCII string with some values represented by charaters 0-9 and a-f.  you want to convert this to a string of decimal numbers or do you want this to be a number.  blue wire (U32)out or red(String)?

 

Either Scan from string or Hexadecimal string to number will return a U32 number.  You can chose to display that number as binary, octal, decimal, or hexadecimal if you wire it to an indicator just select the display propertiesof the indicator!

 

If you really want it as a string use Scan from string or Hexadecimal string to number and number to decimal string  the sample vi doesn't do what you think it does.


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 5
(3,700 Views)

Hi,

 

I agree with Jeff; your vi does (almost) the same as changing the string display from normal to hex. I can't see a use for this in processing the data.

 

To expand a bit on converting to an integer; one of the differences in using scan from string with, say, %4x specifier(s), and using hex string to number is that hex string to number will keep reading until it runs out of hex characters, and in scan from string you can specify how many characters you read. [I simplify slightly] Check out the help messages for both functions for full details.

 

Thus, as I said before you could use scan from string to get three separate intergers even when the hex characters don't have a space between the three numbers. You could ignore any values you don't need to use.

 

Rod.

 

 

 

0 Kudos
Message 5 of 5
(3,678 Views)