Main Content

Set and Measure DAC (Data Acquisition) Channel Voltage on Keysight 34970A Switch Using the IVI-C Driver

This example shows how to initialize the driver, read a few properties of the driver, identify installed cards, set DAC channel output voltage and measure DC voltage using Agilent® Technologies 34970A data acquisition/switch unit and output the result in MATLAB®.


This example requires the following to be installed on the computer:

  • Keysight™ IO libraries version 17.1 or newer

  • Keysight 34970A, 34972A Data Acquisition Switch Unit IVI driver version or newer

Enumerate Available IVI-C Drivers On The Computer

This enumerates the IVI drivers that have been installed on the computer.

IviInfo = instrhwinfo('ivi');
ans = 

  Columns 1 through 6

    'Ag33220'    'Ag3352x'    'Ag34410'    'Ag34970'    'Ag532xx'    'AgAC6800'

  Columns 7 through 11

    'AgE36xx'    'AgInfiniiVision'    'AgMD1'    'AgRfSigGen'    'AgXSAn'

  Columns 12 through 13

    'KtRFPowerMeter'    'rsspecan'

Create MATLAB Instrument Driver And Connect To The Instrument

% Create the MATLAB instrument driver

% Use icdevice with the MATLAB instrument driver name and instrument's
% resource name to create a device object. In this example the instrument
% is connected by GPIB at board index 0 and primary address 1.
myInstrument = icdevice('Ag34970.mdd', 'GPIB0::01::INSTR','optionstring','simulate=true');

% Connect driver instance

Get General Device Properties

Query information about the driver and instrument

Utility = get(myInstrument, 'Utility');
DriverIdentification = get(myInstrument,'Inherentiviattributesdriveridentification');
InstrumentIdentification = get(myInstrument,'Inherentiviattributesinstrumentidentification');
Revision = invoke(Utility, 'revisionquery');
Vendor = get(DriverIdentification, 'Specific_Driver_Vendor');
Description = get(DriverIdentification, 'Specific_Driver_Description');
InstrumentModel = get(InstrumentIdentification, 'Instrument_Model');
FirmwareRev = get(InstrumentIdentification, 'Instrument_Firmware_Revision');

% Print the queried driver properties
fprintf('Revision:        %s\n', Revision);
fprintf('Vendor:          %s\n', Vendor);
fprintf('Description:     %s\n', Description);
fprintf('InstrumentModel: %s\n', InstrumentModel);
fprintf('FirmwareRev:     %s\n', FirmwareRev);
fprintf(' \n');
Vendor:          Agilent Technologies
Description:     IVI driver for the Agilent 34970 data acquisition/switch unit. [Compiled for 64-bit.]
InstrumentModel: 34970A
FirmwareRev:     Sim1.4.0.0

Identify Installed Cards

System = get(myInstrument, 'System');
for iLoop = 100:100:300
    CardType = invoke(System, 'systemgetcardtype', iLoop, 127);
    fprintf('Slot: %d  CardType: %s\n', iLoop, CardType);
    if regexp(CardType, ',34907A,')
        DacSlot = iLoop;
    if regexp(CardType, ',34908A,')     % Single ended -- 40 channels
        MuxSlot = iLoop;
    if regexp(CardType, ',34902A,')     % 16 channel Mux
        MuxSlot = iLoop;
    if regexp(CardType, ',34901A,')
        MuxSlot = iLoop;
Slot: 100  CardType: HEWLETT-PACKARD,34901A,0,1.1 
Slot: 200  CardType: HEWLETT-PACKARD,34901A,0,1.1 
Slot: 300  CardType: HEWLETT-PACKARD,34907A,0,1.1 

Set and Measure DAC Channel 5 Output Voltage

% set DAC voltage to 2.345 V and Select channel 5 on the DAC card
DacVoltage = 2.345;
DacChannel = DacSlot+5;
if DacSlot ~= 0
    % Sets the output voltage level on the DAC channel 5
    Dac = get(myInstrument, 'Dac');
    invoke(Dac, 'dacsetvoltage', DacChannel,DacVoltage);
    % Gets the output voltage level on the DAC channel 5
    DacVoltage = invoke(Dac, 'dacgetvoltage', DacChannel);
    fprintf('DAC channel %d set to %.3f volts\n\n', DacChannel, DacVoltage);
    fprintf('34907A Multifunction Module not found\n\n');
DAC channel 305 set to 2.345 volts

Display Errors

% If there are any errors, query the driver to retrieve and display them.
ErrorNum = 1;
while (ErrorNum ~= 0)
    [ErrorNum, ErrorMsg] = invoke(Utility, 'errorquery');
    fprintf('ErrorQuery: %d, %s\n', ErrorNum, ErrorMsg);
ErrorQuery: 0, No error. 

Disconnect Device Object And Clean Up

% Remove instrument objects from memory.

Additional Information:

This example shows the set and measure DAC channel voltage from an Switch using the IVI driver. Once the measured voltage data is retrieved from the instrument, MATLAB can be used to visualize and perform analyses on the data using the rich library of functions in the Signal Processing Toolbox™ and Communications Systems Toolbox™. Using Instrument Control Toolbox™, it is possible to automate control of instruments, and, build test systems that use MATLAB to perform analyses that may not be possible using the built-in capability of the hardware.