|
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
|