Info

This question is closed. Reopen it to edit or answer.

How do I unfreeze video when toggling between a pair of snapimage and serial communication callbacks?

1 view (last 30 days)
Hello,
I'm building a GUI that is controlling a camera and my hardware connected via serial port in Matlab 2015b. Originally, it was in Matlab 2014a, but due to some installation miscommunication, we have upgraded to 2015b. This problem existed beforehand, but is much more frequent now. I am not sure if the version has any bearing on its frequency, though, but I wanted to mention it just in case.
I have one pushbutton (acquireImage) that grabs a an image from the axes object that displays the camera output. I have another pushbutton (updateStatus) that writes a serial command to the hardware and changes the configuration of the object we are observing. When updateStatus is pushed, it opens the serial communication, sends the message, and then closes the port. The hardware can not send back any message back to the computer to indicate a configuration update has been written, but the change is visually verified.
Both of these pushbuttons function without error when used on their own.
I have a third pushbutton (acquireSequence) that takes an image, updates the system configuration, takes an image, updates the system... et cetera. acquireSequence is meant to collect a set of 10 images as the system steps through each hardware configuration. I currently have it calling updateStatus_Callback and acquireImage_Callback with a pause(1) between each line. Roughly, the pseudocode representation is operated like this:
function acquireSequence_Callback(hObject, eventdata, handles)
for count= 1:10
assignin('base','count',count);
updateStatus_Callback(hObject, eventdata, handles);
pause(0.5);
acquireImage_Callback(hObject, eventdata, handles);
pause(0.5);
end
resetStatus_Callback(hObject, eventdata, handles);
When I manually recreate the behavior described in the above pseudocode, the video never freezes. When I press the acquireSequence pushbutton, the video freezes about 80-90% of the time. Just in case it is relevant, I have included my current video settings for the videoinput() into the axes object is defined like this when the user selects and starts up a camera:
handles.video = videoinput(evalin('base','adapterName'), evalin('base','camNum'));
hold(handles.cameraAxes, 'off')
set(handles.video,'TimerPeriod', 0.05, ...
'TimerFcn',['if(~isempty(gco)),'...
'handles=guidata(gcf);'... % Update handles
'image(getsnapshot(handles.video));'... % Get picture using GETSNAPSHOT and put it into axes using IMAGE
'set(handles.cameraAxes,''ytick'',[],''xtick'',[]),'... % Remove tickmarks and labels
'else '...
'delete(imaqfind);'... % Clean up - delete any image acquisition objects
'end']);
set(handles.video,'ReturnedColorSpace','rgb'); %for color fidelity
triggerconfig(handles.video,'manual');
handles.video.FramesPerTrigger = Inf; % Capture frames until manual stop
My suspicion is there is something wrong with the TimerFcn setting. I originally pulled it from an answer from another thread that I found here a while ago.
Thank you!
Lisa Li

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!