07-17-2013 04:01 PM
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!
Solved! Go to Solution.
07-17-2013 04:08 PM
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.
07-17-2013 05:12 PM - edited 07-17-2013 05:13 PM
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
07-17-2013 05:26 PM - edited 07-17-2013 05:29 PM
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"
07-17-2013 05:43 PM
07-17-2013 06:04 PM
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.
07-17-2013 07:16 PM - edited 07-17-2013 07:21 PM
@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)
07-17-2013 07:29 PM
07-17-2013 08:14 PM - edited 07-17-2013 08:14 PM
Oh I actually had no idea concat can be used for an array! Thank you so much for pointing that out!
To Mr Dennis_Knutson, 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!
07-17-2013 08:23 PM
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.