Function to stop the running serial communication of comport
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2014-3-16
2 个评论
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.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!