Instrument Control Demo

Download MATLAB files: lab1.zip

Contents

Query for hardware information

For general information about the Instrument Control Toolbox, type:

    instrhwinfo
          MATLABVersion: '7.6 (R2008a)'
    SupportedInterfaces: {'gpib'  'serial'  'tcpip'  'udp'  'visa'}
       SupportedDrivers: {'matlab'  'ivi'  'vxipnp'}
            ToolboxName: 'Instrument Control Toolbox'
         ToolboxVersion: '2.6 (R2008a)'

The SupportedInterfaces and SupportedDrivers fields list the interfaces and drivers supported by the toolbox, and not necessarily those installed on your computer.

To display information about a specific interface, you supply the interface name as an argument to instrhwinfo. The interface name can be gpib, serial, tcpip, udp, or visa. For the GPIB and VISA interfaces, the information includes installed adaptors. Example GPIB adaptors are:

advantech, agilent, cec, contec, ics, iotech, keithley, mcc, ni

To obtain information about a specific installed adaptor, you supply the interface name and the adaptor name as arguments to instrhwinfo. This generates a set of instruments in the field ObjectContructorName.

gh = instrhwinfo('gpib','agilent');
disp(gh);
             AdaptorDllName: [1x92 char]
          AdaptorDllVersion: 'Version 2.6.0'
                AdaptorName: 'agilent'
          InstalledBoardIds: [7 8]
      ObjectConstructorName: {3x1 cell}
              VendorDllName: 'sicl32.dll'
    VendorDriverDescription: 'Agilent Technologies GPIB Driver'

Query individual instruments

The following script cycles through the members of ObjectConstructorName, creates an instrument interface object and queries the associated instrument for an identification string. Note the use of fprintf to send commands to the instrument and fscanf to read replies from the instrument.

n = length(gh.ObjectConstructorName);
for (k=1:n)
    str = char(gh.ObjectConstructorName(k));
    obj = eval(str);
    fopen(obj);
    fprintf(obj,'*IDN?');
    idn = fscanf(obj);
    fprintf('\ninterface: %s\n',str);
    fprintf('identification: %s\n',idn);
    fclose(obj);
    delete(obj);
    clear obj;
end
interface: gpib('agilent', 7, 7);
identification: AGILENT TECHNOLOGIES,54622A,US40180420,A.01.01


interface: gpib('agilent', 7, 10);
identification: HEWLETT-PACKARD,33120A,0,8.0-5.0-1.0


interface: gpib('agilent', 7, 22);
identification: Agilent Technologies,34410A,MY45002400,2.21-2.21-0.09-46-6

Open function generator and scope

Now we know the GPIB board index and primary address for each available instrument.

Next we create instrument objects for the desired instruments. Below we setup the function generator and oscilloscope. The fopen command makes the instrument active (like opening a file).

fg = gpib('agilent',7,10);
os = gpib('agilent',7,7);
fopen(fg)
fopen(os)

Configure the function generator

Here is some example code for controlling the function generator. Running this script places the function generator in remote mode (shown on the instrument display). Press the LOCAL button (lower right) to enable manual operation.

fprintf(fg,'APPLY:TRIANGLE 1500, 1');
fprintf(fg,'APPLY?');
query = fscanf(fg);
disp(query);
"TRI 1.500000000000E+03,+1.000000E+00,+0.000000E+00"

Configure the oscilloscope

Here is some example code for controlling the oscilloscope. Note that a normal command (no question mark) for a measurement causes the measurement to appear on the display. A query command (with question mark) returns the desired measured value, but does not change the display.

fprintf(os,':AUTOSCALE')
fprintf(os,':MEASURE:FREQ');
fprintf(os,':MEASURE:VRMS');
fprintf(os,':MEASURE:VPP');
fprintf(os,':MEAS:FREQ?');
freq = fscanf(os,'%g');
fprintf('frequency: %g Hz\n',freq);
fprintf(os,':MEAS:VPP?');
vpp = fscanf(os,'%g');
fprintf('vpp: %g V\n',vpp);
fprintf(os,':MEAS:VRMS?');
vrms = fscanf(os,'%g');
fprintf('vrms: %g V\n',vrms);
frequency: 1501.5 Hz
vpp: 0.9316 V
vrms: 0.26258 V

Close all instruments

This script uses the instrfind function to identify all instruments, closes them and deletes the associated instrument objects.

g = instrfind;
for k=1:length(g)
    fclose(g(k));
    delete(g(k));
end
clear g;

The figure below was obtained by use of the Intuilink Data Capture application:


Maintained by John Loomis, last updated 2 January 2009