Thread Subject: RS232:real time data plot problem

Subject: RS232:real time data plot problem

From: Sai

Date: 14 May, 2010 06:10:05

Message: 1 of 3

      Hi all, I need an application where i need to display current waveform on gui plot in real time. I am sending data from DSP-2812 and using max3232 for logic conversion. I saw some examples for serial communication in this site and they are displaying like oscilloscope. I did the similar thing but used callbacks for BytesAvailableFcn. when no of bytes available=2 call back should execute and update the plot on screen. But there is some problem with invoking of callback and gui screen goes blank while receiving data. Plot is refreshing only after data sending is stopped/paused. To see the plot, every time, i had to stop data sending from dsp. Why this is happening in my case? is there any way to improve delay in calling callbacks?


---my code---
       serialObj=serial('COM1','baudrate',9600,'Timeout',2);
       serialObj.BytesAvailableFcnMode='byte';
       serialObj.BytesAvailableFcnCount=2;
       serialObj.BytesAvailableFcn={@mycallback,handles};
......
......
function mycallback(hObject, eventdata, handles)
    tframe=2; %width of the oscilloscope screen
    global ia count t tocold samples
    if isempty(count)
        count=1;
    end
    try
        x=fread(handles.serialObj,2,'uint8');
        ia(count)=x(1)*256+x(2); %x=[quotient reminder]
        samples(count)=count;
    catch e
        errordlg(e.message);
    end
     count=count+1;
    set(handles.plot1,'xdata',samples,'ydata',ia);
    set(handles.axes1,'xlim',[0 count]...
                      ,'ylim',[min(ia)-1 max(ia)+1]);


Thanks in advance
Sai

Subject: RS232:real time data plot problem

From: Sai

Date: 29 May, 2010 19:45:24

Message: 2 of 3

after so many trails I finally found the solution :) now itz working fine... i made all the variables global and increased BytesAvailableFcnCount to 500. so less processing burden and increased speed.

byee all

Subject: RS232:real time data plot problem

From: Ankit Desai

Date: 29 May, 2010 21:54:05

Message: 3 of 3

"Sai " <skrishna261@gmail.com> wrote in message <htrqsj$7j3$1@fred.mathworks.com>...
> after so many trails I finally found the solution :) now itz working fine... i made all the variables global and increased BytesAvailableFcnCount to 500. so less processing burden and increased speed.
>
> byee all

Hi Sai,

You might want to check out the following demo:

http://www.mathworks.com/matlabcentral/fileexchange/25519-collect-and-plot-data-from-an-instrument-in-real-time

Another trick is to just update the YData on the GUI plot rather than re-plotting the data.

Hope it helps

-Ankit

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
serial Ankit Desai 29 May, 2010 17:59:08
serial Sai 14 May, 2010 02:14:09
callback Sai 14 May, 2010 02:14:09
real time plot Sai 14 May, 2010 02:14:09
bytesavailablefcn Sai 14 May, 2010 02:14:08
rssFeed for this Thread

Contact us at files@mathworks.com