Code covered by the BSD License  

Highlights from
imaqutils

imaqutils

by

 

24 Sep 2004 (Updated )

Convenience functions to find hardware & create objects for supported Image Acquisition devices.

imaqavail(desiredFormat)
function devInfo = imaqavail(desiredFormat)
%IMAQAVAIL returns information about available IMAQ devices.
%   Returns empty if no Image Acquistion Toolbox or devices available.
%
%   DEVINFO = IMAQAVAIL returns a structure array with named fields.
%     .NAME and .CLASS are good for populating a GUI for user selection.
%     .CONSTRUCTOR aids programmatic connection to each device.
%     .ADAPTOR, .ID and .FORMATS help with nondefault object constructors.
%   The length of DEVINFO indicates how many devices detected.  
%
%   DEVINFO = IMAQAVAIL(DESIREDFORMAT) allows specification of the
%   desired video format. This string is inserted into the constructor
%   field for each device. DESIREDFORMAT is not checked, so if you specify
%   an invalid format then evaluating the constructor(s) will error.
%
%Note: This function calls IMAQRESET, which closes and deletes any
%   previously active videoinput objects.
%
%Example:
%   devInfo = imaqavail;    %get basic info for available IMAQ devices
%
%See also IMAQHWINFO, IMAQRESET, plus IMAQCREATE.

% Copyright 2004-2010 RBemis The MathWorks, Inc. 

%TODO List:
%   1. refactor desiredFormat input to PV pair (or remove option)
%   2. consider PV filters (device, resolution, etc)

error(nargchk(0,1,nargin))
error(nargoutchk(0,1,nargout))

%make sure toolbox present
v = ver('imaq');
if isempty(v)
  warning('Image Acquisition Toolbox not available.')
  devInfo = [];
end

%make sure recently added plug-n-play devices also detectable
imaqreset

%installed adaptors
hwInfo = imaqhwinfo;
adaptors = hwInfo.InstalledAdaptors;

%available devices
numDevices = 0;  %start with empty list
for i=1:length(adaptors)  %check each adaptor
  adaptorInfo = imaqhwinfo(adaptors{i});
  devices = adaptorInfo.DeviceIDs;
  %add each device to list
  for j=1:length(devices)
    numDevices = numDevices+1;
    deviceInfo = imaqhwinfo(adaptors{i},devices{j});
    devInfo(numDevices).name = deviceInfo.DeviceName;
    constructor = deviceInfo.ObjectConstructor;
    objClass = constructor(1:(findstr(constructor,'(')-1));
    devInfo(numDevices).class = objClass;
    if nargin>0  %add format to object constructor
      constructor = [constructor(1:end-1) ', ''' desiredFormat ''')'];
    end
    devInfo(numDevices).constructor = constructor;
    devInfo(numDevices).adaptor = adaptors{i};
    devInfo(numDevices).id = devices{j};
    devInfo(numDevices).formats = deviceInfo.SupportedFormats;
  end  %for j = devices
end  %for i = adaptors

%return empty idicator if no devices detected
if numDevices==0
  devInfo=[];
end

%pretty print results (if no return argument)
if nargout==0 && ~isempty(devInfo)
  if strcmp('loose',get(0,'FormatSpacing'))
    fprintf('\n');
  end
  fprintf('   Index:   Adaptor:   Id:   Name:\n'); %cols 3 12 23 29
  for i=1:length(devInfo)
    fprintf([blanks(5) '%d'],i);            %Index number
    if i<10, fprintf(' '); end
    adaptor = devInfo(i).adaptor;
    fprintf([blanks(5) '%s'],adaptor);      %Adaptor name
    fprintf(blanks(11-length(adaptor)));
    id = devInfo(i).id;
    fprintf(['%d'],id);                     %Id number
    if i<10, fprintf(' '); end
    fprintf(blanks(12-length(adaptor)));
    fprintf('%s\n',devInfo(i).name);        %Name
  end
  fprintf('\n');
  clear devInfo
end

Contact us