Statusbar parallel with computation and motors
2 views (last 30 days)
Show older comments
Hellow, my programm works with two motors that acquite data and while this happens i want a statusbar in my gui to see how much time is already done an how mutch is remaining. I downloaded a statusbar at http://www.mathworks.com/matlabcentral/fileexchange/5912-status-progress-indicator but can't get it worked in parallel. It works always in serial way :(
Here is my code:
function StartRecon_Callback(hObject, eventdata, handles)
% hObject handle to StartRecon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
t = serial('COM1','BaudRate',57600,'DataBits',8,'Stopbits',1,'ErrorFcn','Fout opgetreden!','Parity','none','FlowControl','none'); % rotations- motor
u = serial('COM3','BaudRate',112500,'DataBits',8,'Stopbits',1,'ErrorFcn','Fout opgetreden!','Parity','none','FlowControl','none'); % microprocessor
fopen(t)
fopen(u)
set(u,'TimeOut',1)
load(['variables/meet.mat'])
stappen = round(ang/0.9); % 1 step = 0.9° => calculate steps
step = rotations/120; % divide 120 for 1 second per projection
data_inten = zeros(as,1);
inten = zeros(rotations,16)
s=0;
% for every slice
for i=1:as
%set statusbar for every slice
stat = [ 'Scanning Layer ' int2str(i) ' ...'] %
f=statusbar(stat);
for p=0:0.01:1
pause(stp); %wait
if isempty(statusbar(p,f))
break;
end
end
i=0;
% hier komt inlezen en verdraaien van de motor en micorcontroller
for r=1:rotations
fwrite(u,'5') % send 5 to receive data
data = fread(u,34) % receive 34 bytes
j=0;
for k=2:2:32 % convert binary data to intensitys
str = dec2hex(data(k))
st = dec2hex(data(k+1))
string = strcat(st,str)
c = hex2dec(string)
inten(r,j+1) = c*610*10^-6
j=j+1
end
s=s+stappen;
if r < rotations % if r smaller than max rotate
strm = [ 'p' int2str(s) '.' ] ;
fprintf(t,strm)
end
end
data_inten{as}=inten; %set all data in data_inten
% if end statusbar ask new slice
if ishandle(f)
delete(f);
text = [ 'Change height for ' int2str(ls) ' mm']
if ( i < as)
uiwait(msgbox(text,'Wait','modal'));
end
if i == as
uiwait(msgbox('Acquisition successfully done!','Acquisition Done','Help Icon'))
end
end
end
save(['variables/meet.mat'],'data_inten','-append')
fclose(t)
fclose(u)
delete(t)
delete(u)
open('DA_done.fig')
close(gcbf)
0 Comments
Answers (3)
Ivan van der Kroon
on 18 May 2011
I addapted the example in the statusbar.m to show you can have them active simultaniously:
f=statusbar('Wait some seconds ...');
g=statusbar('Second wait ...');
for p=0:0.01:1
pause(0.2);
if isempty(statusbar(p,f))
break;
end
if isempty(statusbar(p,g))
break;
end
end
if ishandle(f)
delete(f);
delete(g);
end
Just remeber to call the correct figure handle. Also note that they will be plotted at the same position, so if you want to see them in different positions, change the positions.
Btw, nice to keep your Dutch comments!
0 Comments
Ivan van der Kroon
on 18 May 2011
To clarify a few things:
1) you have 3 for-loops (indexes i, r and p) where the first includes the others. Where exactly doe you want to have a statusbar?
2) the pause in the example in statusbar.m is just some arbitrary thing that takes time. The process what you want to monitor goes instead of that. Right now, your m-file is just waiting 0.2s every iteration.
3) i is changed inside its loop. To 0 (!) so it will never end. What do you want to do here?
If I correctly guess what you want here is to put two bars next to each other. Next introduce 3 for-loops (i,r and p) with the first including the others. The first bar will manage i and the second r.
I=4;P=1;R=10;
f=statusbar('Wait some seconds ...');
fpos=get(f,'position');
for i=1:I
% process#1
pause(rand(i))
for p=1:P
% process#2
end
g=statusbar('Second wait ...',g);
set(g,'position',fpos+[fpos(3) 0 0 0])
for r=1:R
% process#3
pause(0.1)
if isempty(statusbar(r/R,g))
break;
end
end
if isempty(statusbar(i/I,f))
break;
end
end
if ishandle(f) && ishandle(g)
delete(f);delete(g);
end
Replace '% process#' by what you want to do there and remove the pauses because it is just an example of a matlab process be going on there. Note that the input to statusbar should be between 0 and 1.
Veel succes!
0 Comments
Communities
More Answers in the Power Electronics Control
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!