Clear Filters
Clear Filters

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

2 views (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
source= videoinput('winvideo');
set(source, 'ReturnedColorSpace', 'RGB');
set(source, 'FramesPerTrigger', 1);
set(source, 'TriggerRepeat', inf);
triggerconfig(source, 'manual');
if get(handles.startstop,'Value')
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, and it also does not delete the video object; see 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.
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);
handles.source = [];
guidata(gcbo, handles

Sign in to comment.

More Answers (0)


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!