I'm trying to use a toggle button to start and stop video acquisition but i get the following error. Could any1 help???

1 view (last 30 days)
Trying to use a simple toggle button to start and stop my video processing i get an error.
my code under that of the toggle button being
% Hint: get(hObject,'Value') returns toggle state of startstop
clc;
source= videoinput('winvideo');
set(source, 'ReturnedColorSpace', 'RGB');
set(source, 'FramesPerTrigger', 1);
set(source, 'TriggerRepeat', inf);
triggerconfig(source, 'manual');
start(source);
pause(2);
trigger(source);
if get(handles.startstop,'Value')
set(handles.startstop,'String','Stop');
set(handles.startstop,'Value',1);
drawnow();
else
set(handles.startstop,'String','Start');
set(handles.startstop,'Value',0);
clear(source);
stop(source);
end
i get the following error
??? Error using ==> imaqdevice.start at 91
Multiple VIDEOINPUT objects cannot access the same device simultaneously.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Jan 2013
When you push the toggle button to start the video, you create the videoinput(). Then when you push the button to stop the video, you again create the videoinput.
When you have a togglebutton, the code does not somehow wait around for the togglebutton to change state and then continue. Instead each time you push the togglebutton, the entire callback is executed.
You need to find a way to save the value of "source" somewhere so it can be available for when you are turning off the video.
Note: clear() must be applied to a variable name, and after you clear the variable, it will no longer be in the workspace to be available to stop(). clear() does not stop a video object; see http://www.mathworks.com/help/imaq/clear.html, and it also does not delete the video object; see http://www.mathworks.com/help/imaq/delete.html. You should stop the object, and delete it. If it is a local variable then you do not need to clear it as the local reference will go out of scope when the function returns.
  8 Comments
Sanjeev
Sanjeev on 27 Jan 2013
thanks Walter. ur code is working perfectly. if u dont mind could you explain what the codes u added does exactly??
handles.source = source;
guidata(gcbo, handles);
drawnow()
handles.source = [];
guidata(gcbo, handles

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!