How to handle timer

6 views (last 30 days)
Happy PhD
Happy PhD on 17 Feb 2020
Commented: Jon on 19 Feb 2020
I have a program in app designer, for which I have a camera that is showing live feed with a timer. See example below,..
% timer for plotting camera image
function CreateImageTimer(app)
app.timerImage = timer;
app.timerImage.StartDelay=1;
app.timerImage.ExecutionMode='fixedSpacing'; % 'fixedDelay'; %
app.timerImage.Period = 0.001;
app.timerImage.TimerFcn = @(~, ~)PlotImage(app);
app.timerImage.StopFcn = @(~, ~)CleanUpImageTimer(app);
end % end function
function CleanUpImageTimer(app)
delete(app.timerImage)
end % end fucntion
function PlotImage(app)
%tic
if(~isempty(app))
if (isempty(app))
delete(imaqfind);
end % end if
if (app.ButtonCamera.Text=='Stop Camera')
%disp('frame')
%clear('app.frame')
%axesHandlesToChildObjects = findobj(app.Video, 'Type', 'image');
% if ~isempty(axesHandlesToChildObjects)
% delete(axesHandlesToChildObjects);
% end
[app.frame, app.timeStamps]=snapshot(app.VidObj);
app.frame = app.frame; %*(2^16/2^12);
imagesc(app.Video, app.frame);
drawnow
% (more code...)
end
end
I also have a screip to control a translation stage using NET.addAssembly, which I call to move to a certain position.
My issue is that in a scan of different position (or any movement of the translation stage) the camera is still (not taking images), that is the timer seem to not be functioning simultaneously as the translation stage is moving.
Any idea why and how I can have the camera to continuously to take pictures during movement of the trsanslation stage or at least pasue the timer until the stage has reached its end position?
Is this possible?
Get a lot of errors like
Error while evaluating TimerFcn for timer 'timer-23'

Accepted Answer

Jon
Jon on 17 Feb 2020
You probably have some error in the code, PlotImage, that the timer is calling. Debugging problems in timer functions is a little tricky because the error message doesn't give much detail about where the error occurs.
I have found it helps to wrap the entire contents of the function that the timer calls in a try-catch block.
Also you can try just calling the PlotImage function with a separate test script, or command line call, not using the timer to see what errors come up.
Also it looks like you have a lot of timers, the error is for timer-23, are you sure you are stopping and deleting your old timers when you are done with them?
  8 Comments
Jon
Jon on 19 Feb 2020
Well, hope you can crack it, good luck with your research!

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by