Function to stop the running serial communication of comport
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 16 Mar 2014
2 Comments
Walter Roberson
on 16 Mar 2014
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.
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!