How can I tell if a frame grabber is in use by another application with Image Acquisition Toolbox?
3 views (last 30 days)
Show older comments
I use my image acquisition hardware with multiple applications. I would like to be able to query the device from MATLAB to see if it is currently in use by the other application.
With one of my winvideo devices, if it is in use by another application, IMAQHWINFO returns an empty cell array when the device is in use. For example:
x=imaqhwinfo('winvideo')
returns
x =
DeviceIDs: {1x0 cell}
DeviceInfo: [1x0 struct]
This is not the case with other devices.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
A function to determine if image acquisition hardware is in use by another application is not available in Image Acquisition Toolbox.
The behavior of the winvideo adaptor described above is not universal to all winvideo devices and can not be expected to work for other drivers or even the same winvideo device under different circumstances. In most cases, the function IMAQHWINFO still returns a device ID even when the device is in use.
To workaround this issue you can tell that a device is in use when you receive an error while attempting to access the device. For example when a device is in use and you attempt to create a video input object
v=videoinput('winvideo', 1)
you may receive the error
??? Cannot access information on the image acquisition device.
One or more arguments are invalid
Make sure no other objects or applications are accessing the same device.
Please note that this command will not always fail, but subsequent image acquisition commands may fail with similar error messages.
available
To gracefully catch this error, you can enclose the commands in a try-catch block. For example
result = 'Try Again';
while strcmp(result,'Try Again')
try
v=videoinput('winvideo', 1);
h = preview(v);
result = 'Success';
catch
delete(v)
result = questdlg(['Image acquisition device is not available. '...
'It may be in use by another application.'],...
'Error Accessing Hardware','Try Again','Abort','Try Again');
end
end
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!