LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about reading hex data

Solved!
Go to solution

Hello! I am a Labview Novice and having a problem about reading hex data.

Basically I am having bytes from the serial port like this: "80100E0E0AB4F646F24A00911267087E032080057FFF "

It is not encoded in ASCII. What I want to do is to convert the hex to an ASCII hex string.

so that the string would become hex numbers in ASCII.

I think the following might be a solution, but I have no idea what the subvi is in the solution.

 

http://forums.ni.com/t5/LabVIEW/Hex-String-to-Ascii-Hex-String/m-p/886078/highlight/true#M400462

Thanks in advance and I appreciate your kind help!

0 Kudos
Message 1 of 13
(4,026 Views)

Are you now saying that the data is coming in differently from what you described in your first post?  http://forums.ni.com/t5/LabVIEW/data-type-problem/td-p/2494434

 

Attach a VI where you have the actual data that comes inf rom the device saved in a string control.  Save the data as the default data for the control.  Save the VI.  Attach your VI to the post.

 

Is your data supposed to be U32 integers like you have in your original post?

 

Try wiring your string data to a typecast function with a U32 array wired into the top of it to define the datatype.

 

0 Kudos
Message 2 of 13
(4,023 Views)

RIght, my last post is the second part of the solution to the problem. 

I have difficulty obtaining the data at the moment, as I don't have access to the instruments this week.

What I have is bytes of data, each byte corresponds to 2 numbers, each number having 4 bits to be represented, which means 2^4 = 16. 
So each of my byte stores 2 hex integer. My string is like this:

"80100E0E0AB4F646F24A00911267087E032080057FFF"

 

80 and 10 are the heading byte, which means start of transmission.

0E0E is my first set of data, magnetic field in x direction, which should be interpreted as 3598 in decimal

 

What I am planning to do, is to convert this stream of Hex into ASCII Hex, then I would be able to use my previous program to turn them into separate real numbers in double precision. (by getting rid of 8010 in the front and extracting data every 4 character)

 

Have you visited the website I posted and do you know what is the SubVi mentioned?

Thanks so much again! Appreciate your kindness

0 Kudos
Message 3 of 13
(4,013 Views)

The segment of the program controlling the serial port is as follow, written in Dynamic C (an advanced version of C):

sprintf(&output[bytenum],"%02X",mx[0]); bytenum+=2;
sprintf(&output[bytenum],"%02X",mx[1]); bytenum+=2;

 

where mx is of the type char[2]. I wrote what I read from the sensor to mx.

what the sensor gives is the bytes I described above, hex numbers.

I want to achieve the same function as the segment above, in Labview..

Thz so much!!!



Or, to make it easier to understand, it is a string, when displayed in "Hex Display" format, like this

"80100E0E0AB4F646F24A00911267087E032080057FFF"

0 Kudos
Message 4 of 13
(4,007 Views)
It makes no sense when you say you want to convert to ASCII hex.

From your description, I would suggest using the string to byte array function. You would index the elements you need, combine as needed, and typecast.
0 Kudos
Message 5 of 13
(3,997 Views)

What I want to do is actually this.

I thought it might be more convenient to use the SubVi mentioned in the website, but anyway I got it.

Thanks anyway buddy.

0 Kudos
Message 6 of 13
(3,991 Views)
Solution
Accepted by topic author coolmatthew

@coolmatthew wrote:

What I want to do is actually this.


You are using way too much code for all this. All you need is a concatenate strings, replacing your entire loop and such. Same result. 😄

 

 

 

(see also)

Message 7 of 13
(3,981 Views)
So what is the point of converting a string to another string? You said you wanted a number.
Message 8 of 13
(3,973 Views)

Oh I actually had no idea concat can be used for an array! Thank you so much for pointing that out!Smiley Surprised

To Mr , I wanted to change it to ASCII Hex, so that my previous program can be used to get rid of the 80 and 10 in the beginning of the string.

Thz anyway for your generous help!

0 Kudos
Message 9 of 13
(3,967 Views)


Then, I would just use string subset to get rid of the first 2 characters of the string.

 

Or you could use Match Pattern like you did in your other message thread.  Instead of searching for the 10 as 2 characters in a string constant set for normal display, change your string constant to hex display and enter 80 10 which will look for those 2 bytes.

Message 10 of 13
(3,957 Views)