LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing data from serial port into Arrays

I quite new to LabVIEW so I apologize if what I write about is remedial.

 

I have a few questions regarding serial communications.  I'll be reading in data from a microprocessor that is sending information to a PDA.  For now, the PDA and microprocessor are connected via RS-232 serial.  If I send data from the microprocessor (with headers & footers), is there a way I can setup LabVIEW to recognize these headers and footers?  For example:  if my header is <00> followed by data 1234, then a footer, <0F>, how can "parse" my data to put each new piece of data into a new cell in a 1-n array?  "n" represents the number of headers (or footers).  I hope this makes sense.  I am attaching a picture of what I need.

 

I basically want to know what I need to put in the box, "LabVIEW Parser."  Is there anyone that can help me, or show me which functions I should use.
Amal Patel
0 Kudos
Message 1 of 33
(10,859 Views)
I guess you are reading your data in a loop.
 
For each string, convert it to a number using "decimal string to number" with an offset of 1 (or whatever your header size is).
Wire the resulting number to the right loop boundary and make sure the tunnel is set to autoindexing. Now your numbers will automatically turn into an array containing one element for each iteration of the loop. 🙂
 
See how far you get.
Message 2 of 33
(10,841 Views)
Hi, I'm doing something similiar, sending data from my pic16f877 to my com port. I'm using a 12bit ADC so my data is seperated into 2 bytes(range 0000-0FFF). This results in the program sometimes recognising different value(fluctuates although i send in a constant, i think is sometimes it takes in FF0F or 0FFF is i actually send in 0FFF). I though of putting a header and footer too like send AB 0F FF AC, then check for AB and CD so I'll know that the data in between is definitely what i want. Any idea how do I do it? Thanks in advance!!

Message Edited by ghostz13 on 02-08-2007 01:34 AM

0 Kudos
Message 3 of 33
(10,505 Views)
Does your data have a termination character like <CR>?
 
If it does you can use that to seperate your data.
 
Good Luck
0 Kudos
Message 4 of 33
(10,471 Views)
Hi, I've a terminating "\n\r" for every 2 bytes sent (ie 0000\n\r), how do i make use of it? Currently I'm using the Visa read then outputting it to a Hex String to Number box connected to a waveform chart. Thanks again!

0 Kudos
Message 5 of 33
(10,464 Views)
ghostz13,
 
You set the termination character when you configure the serial port.  See image.  I'm not a 100% how the <CR> is going to be handled if you terminate on the line feed.
 
Anyway the block diagram read your two bytes of data and converts it to a U16 number then plots it on a graph.
 
I hope this is what you are looking for,  if not post a screen shot of what you have so far and i'll see if I can help you some more.
 
Good Luck
Eric
0 Kudos
Message 6 of 33
(10,436 Views)
Thanks for reply Eric,

I've edited my pic to output voltage level in millivolts. Reason being u remove the problems in dealing with a decimal point and I'm able to view my voltage levels in hyperterminal and reduces problems converting hex to float while coding in Labview. In hyperterminal it receives data just fine. Eg, 0903, 1020, 5000.

When i use Labview, i think sometimes the data get truncated like in the hex case. for example, 100 when 2100 is sent (or something like tat) I'm sampling data with my pic at a rate of 250Hz (every 4ms). Also a lot of the times when I look at the Voltage reading indictor, its value is my default set as 0.

I've looked up the forum and connected the Bytes at Port to the Byte Count (# of bytes to eat) but it doesnt seem to solve my problem. The buffer just cannot cope with the data rate. I've though of whether to create data checks to see that there are 4 digits in the string but I'm new to labview and how to carry out such data processing. Is there a VI I can use or is there any other way? Thanks in advance!!!

Plotter image


Regards,
Gerard

Message Edited by ghostz13 on 02-27-2007 07:53 AM

0 Kudos
Message 7 of 33
(10,317 Views)
Gerard:
 
I was not able to make much sense of your block diagram because of the low picture resolution. Please post your VI or an image of your block diagram so that I can help you further.
 
Thanks,
 
Rudi N.
0 Kudos
Message 8 of 33
(10,263 Views)

Sorry I haven't replyed sooner, been busy at work.

Now that you have modified your string to output ascii characters it should be easier to process.  Are you still using a line feed with a carraige return at the end of each line?  Since you can modify the data coming from your PIC I'd recomend you use one or the other not both.

With that you could us the serial read as you had in your example and use the string to array function to convert it to a number.

I'll try to put an example together this weekend and post it on Monday.  Let me know if you have any new ideas.

One final question, what baud rate are you using?

Eric

Message Edited by arvin labrat on 03-01-2007 10:50 AM

0 Kudos
Message 9 of 33
(10,245 Views)
Gerard,
 
Had a few extra minutes and decided to try something.
 
If your reading data in at 4 ms intervals you are starting to ask for trouble if you try to read each data point indvidually.
 
The example I attached read groups of strings and converts them into an array.
 
Notice on the Serial config I disabled the termination character so it will read whatever is in the serial buffer.
 
Also there is a case statement after the bytes at port.  This will allow the graph to update only when there is data in the serial buffer otherwise it does nothing.
 
I hope this help.  Let me know it it works for you.
 
Good Luck
Eric
Message 10 of 33
(10,223 Views)