Code covered by the BSD License  

Highlights from
instrSelector

image thumbnail

instrSelector

by

 

22 Dec 2008 (Updated )

GUI selection tool for instrumentation connected via VISA.

instrSelector
function [visaVendor, visaAddress] = instrSelector
%INSTRSELECTOR GUI selection tool for instrumentation registered with VISA 
%software.
%   [visaVendor, visaAddress] = INSTRSELECTOR launches a GUI selection tool 
%   that automatically finds instrumentation registered with VISA software
%   and allows the user to select an instrument resource from a menu.  The
%   visaVendor variable is the vendor of the VISA software.  The 
%   visaAddress variable is the VISA address (or Resource Name) of the 
%   instrument.  The VISA address usually follows the following syntax:
%   
%   PROTOCOL::RESOURCE ADDRESS::inst0::INSTR
%
%   For example,
%
%       TCPIP0::144.212.211.210::inst0::INSTR
%
%   identifies an instrument connected via TCP/IP at IP address
%   144.212.211.210.
%
%   The output of the function can be used to create an interface object.  
%
%   EXAMPLE:
%       [visaVendor, visaAddress] = instrSelector
%       interfaceObj = visa(visaVendor, visaAddress);
%
% 	Author: Isaac Noh
%   Copyright The MathWorks, Inc.
%   December 2008
%   Version: 1.0

% Set default values as empty
visaVendor = '';
visaAddress = '';

% Find installed VISA adaptors
Vendor = instrhwinfo('visa');
Vendor = Vendor.InstalledAdaptors;

% Create GUI
h.f = figure(...
    'Units','characters',...
    'Color',[0.8 0.8 0.8],...
    'MenuBar','none',...
    'Name','instrSelector',...
    'NumberTitle','off',...
    'Position',[10.8 25.5 48.8 12],...
    'Resize','off',...
    'HandleVisibility','callback');

h.p1 = uicontrol(...
    'Parent',h.f,...
    'Callback',{@loadInstr,Vendor},...
    'Units','characters',...
    'Position',[9.8 8.2 30.2 1.7],...
    'String',Vendor,...
    'Style','popupmenu',...
    'Value',1,...
    'Tag','edit1',...
    'BackgroundColor',[1 1 1],...
    'HorizontalAlignment','left');

h.p2 = uicontrol(...
    'Parent',h.f,...
    'Units','characters',...
    'Position',[9.8 5 30.2 1.7],...
    'String',{  'Select Device' },...
    'Style','popupmenu',...
    'Value',1,...
    'Tag','edit2',...
    'BackgroundColor',[1 1 1],...
    'HorizontalAlignment','left');

uicontrol(...
    'Parent',h.f,...
    'Units','characters',...
    'Callback','',...
    'Position',[15.4 1.3 18.4 1.8],...
    'String','OK',...
    'Tag','OK',...
    'Callback',{@OK});

uicontrol(...
    'Parent',h.f,...
    'BackgroundColor', [0.8 0.8 0.8],...
    'Units','characters',...
    'Position',[10 9.9 13.5 1.3],...
    'String','VISA Vendor',...
    'Style','text',...
    'Tag','text1');

uicontrol(...
    'Parent',h.f,...
    'BackgroundColor',[0.8 0.8 0.8],...
    'Units','characters',...
    'Position',[8.5 6.7 18 1.15],...
    'String','VISA Address',...
    'Style','text',...
    'Tag','text2');

loadInstr(h.p1,[],Vendor);
uiwait(h.f);

    function loadInstr(hObject,eventdata,Vendor)                            %#ok
        Val = get(hObject,'Value');
        % The second argument below is the vendor of the VISA software you 
        % have installed
        hwinfo = instrhwinfo('visa',Vendor{Val});  
        AllAddress = hwinfo.ObjectConstructorName;
        
        if isempty(AllAddress)
            set(h.p2,'String',{'No Devices Connected'});
            return;
        end
   
        ioresourcedescriptor = regexp(AllAddress, '[\w|\.|:|-]*''', 'match'); %split at the '
        len = length(ioresourcedescriptor);
        visaresource{len} = '';   % Pre-allocate memory
        for ind = 1:len
            rawresource = ioresourcedescriptor{ind}(4);
            visaresource{ind} = rawresource{1}(1:end-1);
        end
        set(h.p2,'String',visaresource);
        
    end %loadInstr --------------------------------------------


    function OK(hObject,eventdata)                                          %#ok
        
        % Extract response
        visaVendor = get(h.p1,'String');
        visaVendor = visaVendor{get(h.p1,'Value')};
        visaAddress = get(h.p2,'String');
        visaAddress = visaAddress{get(h.p2,'Value')};
        
        close(gcf);
        
    end %OK ---------------------------------------------------------

end %instrSelector --------------------------------------------

Contact us