LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to plot data sent through serial port

Hi guys
I am new in Labview so my quiestion could be  easy for someone.
 I ve got a micro which perform ADC conversion  from linear  image sensor which has 1024 pixels. Then micro send 1024 bytes of data  through serial port, so each byte corresponds to one  pixel. I have got basically succesfull waveform graph but everytime when I start reading serial port my picture is not stable, it needs sort of  synchronization.  I suspect I need to send a termination character at the end of each  frame, find this character and then do plotting only. I used "String to Array Byte"  for data plotting. Appreciate for any suggestions.
0 Kudos
Message 1 of 13
(6,146 Views)
Hello,
 
I think I understand fundamentally what you're doing, and the reason for the unstable picture could be a couple of reasons.  You mention you are basically getting data in 1024 byte pieces (of course your serial port is getting them byte by byte, but the 1024 byte pieces constitute your "linear image" if I understand you correctly).  Either of the following could cause an unstable picture:
 
1. You are updating the graph with a few pixels at a time, causing the picture to be constantly changing and updating - to solve this you should read 1024 data points and only update your plot with the whole 1024 points at a time... this will also cause fewer screen updates, and possibly thread swaps, making your code generally more efficient.
2. You are reading your data in 1024 byte chunks, and you actually ARE receiving a termination character - in this case that termination character is probably being read as part of your data and it causing things to look a bit off... to solve this, you should configure your serial port to use termination, and specify the termination character which your device sends with the data... then the result of your read operation will read up to and including that termination character, and you can simply remove that last byte from the string you read before converting to a byte array and plotting (or you could remove it from the array after converting).
3.  If you are trying to read your data and update it in real-time... where you expect to see the 1024 pixel "frames" played one after the other, then how the data is transmitted will also affect the display, since you can only display it once you have it all.  Basically, if you can configure your device to transmit at a higher baud rate (and you would then have to do the same for your COM port, but you can do this using the VISA configure serial VI... I presume you are using VISA to communicate with your serial port), then you can receive your data faster and perhaps that will "smooth" out your plot.
 
Ok, those are a few ideas... I hope this helps!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 2 of 13
(6,133 Views)
PS - one more detail about item 2 in the previous post - if you configure the port to use termination, don't also configure it to read 1024 bytes, because then your read operation will terminate after reading the 1024 bytes on the first iteration, then the next thing in the buffer is going to be a termination character, so your next read will terminate after reading only that byte!  You should set the number of bytes to read to something higher than 1024 in this case, so that the termination character is what causes the read operation to terminate.  Generally a read operation on a serial port read will complete on one of 3 conditions:
 
1. you read the number of bytes specified
2. you receive a termination character (this will cause the read operation to complete IF you have termination enabled)
3. an error occurs (such as a timeout error)
 
I hope this helps!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 3 of 13
(6,133 Views)
Thanks JLS for your response!
Couple more things I would like to point out.
1. When I try to read a buffer I ve got error messages regarding framing, i ve got this messages twice -three times before my waveform become stable. As far as I would say "communication established'' then I have a good stable picture. I am using VISA 115200 baud rate and currently  I am not sending a termination character. But if I stop and try to read buffer again my picture has shifted, so I would say my pixel 1 value is located at place where say my pixel 820 should be. 
Further more if I try to increase or decrease serial buffer size to read  the waveform starts moving. So basically as you suggested I have to use a terminator.
0 Kudos
Message 4 of 13
(6,127 Views)
Hello,

Framing errors usually occur because baud rate settings in software and hardware don't match; make sure the baud rate you set using VISA matches the baud rate of your instrument. Also, as JLS suggested, consider sending a termination character after every 1024 byte chunk., to ensure that with each read, you are getting complete frames that don't overlap.
Be sure to take a look at JLS's second post about using termination and configuring number of bytes to read. Hope this helps.

Regards
Ebele O.
National Instruments
0 Kudos
Message 5 of 13
(6,099 Views)
hi, i know this thread seems rather old but it's the closest related to my current problem.
i'm also sending data from PIC to the pc through serial communication. i'm using the adc of the pic to convert analog input into 10-bits which means values ranging from 0 to 1024 then send it through serial.

here are some of the problems i face:
1. the plotting of graph problem similar to this thread's initial post
2. write to file - i can manage to write the data into text file but all the data is written horizontally.. how do i make it vertical?
3. display of the values on the string display is decided by the number of bytes to read.. how do i make it read up till the termination character (\n i assume) then jump to the next data because the number of bytes of each data varies from 1 to 4 digits because the values range 0 to 1024?

i've read some of the previous post but i dun quite understand so i've attached my vi file for easier reference to see my mistakes in the vi.

thx alot

regards,
Wen Keat.
Regards,
Wen Keat
0 Kudos
Message 6 of 13
(5,790 Views)

Hi Wen Keat,

Insert a carriage return line feed at the end of your string before writing to the file. Use the VISA drivers, there is a property node available to know how many bytes are available to read.

Mike

0 Kudos
Message 7 of 13
(5,787 Views)
thx for the suggestion mike but when i add the carriage return line feed i get the error of the wire having more than one data source.
Regards,
Wen Keat
0 Kudos
Message 8 of 13
(5,782 Views)

Hi wenkeat,

to add the carriage return linefeed you have to use the "Write to Text File.vi"

Mike

0 Kudos
Message 9 of 13
(5,774 Views)
i'm still having problems with the graph display.. it's displaying a weird graph.. anyone can help? thx
Regards,
Wen Keat
0 Kudos
Message 10 of 13
(5,754 Views)