Function to stop the running serial communication of comport
이전 댓글 표시
Hello,
The serial communication using comport is working fine and the main lines of code are
s1 = open_com_port(com_port);
gui_update_freq_divisor = 20;
flushBytesThreshold = 500;
k = 1;
pulse_count=0;period(20)=0;results(100)=0;max1=0;
while ~s_quitgui
nb = s1.BytesAvailable;
if nb > flushBytesThreshold
error('serial data overflow')
end
if(nb)
currtime(k) = sampleCounter*dt;
[tline,count] = fgetl(s1);
data_tmp = str2num(char(tline));
data(k)=(data_tmp);
if s_writetofile
fprintf(FID,'%f %f \n',currtime,data);
end
% update gui not so often
if (~mod(sampleCounter,gui_update_freq_divisor))
for i=1:1:20
if (data(i)==4095)
results(i)=1;
else
results(i)=0;
end
end
max1=max(results);
axes(rawax_gyr)
set(raw1_gyr,'XData',[get(raw1_gyr,'Xdata') currtime]);
set(raw1_gyr,'YData',[get(raw1_gyr,'YData') data]);
% Slide x-axis of the smaller axes
set(rawax_gyr,'XLim',[currtime(1)-10 currtime(1)])
set(rawax_gyr,'YLim',[-10 5000])
k = 0;i=1;
%drawnow
end
sampleCounter = sampleCounter + 1;
k = k + 1;
end
%pause(0.0001);
end
delete(s1)
close(fh)
end
But what are the lines(command) needed to stop the serial communication of COMPORT.
I am planning to implement this a GUI and for start button the serial communication starts but can I know what are the needed lines in the pushbutton call back fucntion so that it stops the communication when stop button is pressed .
댓글 수: 4
Walter Roberson
2014년 3월 15일
Please explain the difference between this question and your earlier http://www.mathworks.co.uk/matlabcentral/answers/121610-adding-stop-button-to-stop-the-data-streaming-from-comport-to-gui-builder
Gova ReDDy
2014년 3월 15일
편집: Gova ReDDy
2014년 3월 15일
Walter Roberson
2014년 3월 15일
Undefined function or variable s_quitgui
Gova ReDDy
2014년 3월 16일
편집: Gova ReDDy
2014년 3월 16일
답변 (1개)
Walter Roberson
2014년 3월 16일
0 개 추천
댓글 수: 2
Gova ReDDy
2014년 3월 16일
Walter Roberson
2014년 3월 16일
You are trying to set a quit flag in one routine and you are trying to read the quit flag in another routine. The FAQ talks about how to share information between routines.
카테고리
도움말 센터 및 File Exchange에서 General Applications에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!