Contents

Reading Waveforms from an Oscilloscope using IVI-COM Drivers

This example shows how to communicate with an oscilloscope using the IVI-COM instrument driver.

The Instrument Control Toolbox™ product supports communication with instruments through low level interfaces and high level drivers. In this example you acquire analog and digital waveforms from an Agilent Technologies® mixed signal oscilloscope (MSO) MSO6014 using an IVI-COM driver.

For a complete list of hardware supported by the toolbox, visit the Instrument Control Toolbox homepage at www.mathworks.com

Introduction

For this example you require a 32 bit MATLAB®, VISA and the 546XX IVI-COM driver version 1.3.8.0. Make sure the VISA utilities recognizes the MSO before you use this example.

Use a function generator to create two wave forms. For Feed a sine wave to Analog channel 1 of the oscilloscope. Feed a square wave to Digital Channel 1.

Get Information about the Instrument

Use INSTRHWINFO to find the instrument and confirm that all requirements are met.

Confirm that VISA is installed.

instrhwinfo('visa')
ans = 

    InstalledAdaptors: {'agilent'  'ni'}
       JarFileVersion: 'Version 2.7.0'

Confirm that VISA is identifying instruments.

instrhwinfo('visa', 'agilent')
ans = 

             AdaptorDllName: [1x93 char]
          AdaptorDllVersion: 'Version 2.7.0'
                AdaptorName: 'AGILENT'
           AvailableChassis: []
       AvailableSerialPorts: {'ASRL1'}
          InstalledBoardIds: []
      ObjectConstructorName: {3x1 cell}
                SerialPorts: {'ASRL1'}
              VendorDllName: 'agvisa32.dll'
    VendorDriverDescription: 'Agilent Technologies VISA Driver'
        VendorDriverVersion: 1

Create the MATLAB® Instrument Driver

Find installed IVI drivers and shared components.

IviInfo = instrhwinfo('ivi')
IviInfo = 

                  LogicalNames: {'hg'  'log'  'Unnamed'  'Unnamed(1)'}
                    ProgramIDs: {1x20 cell}
                       Modules: {1x11 cell}
    ConfigurationServerVersion: '1.6.0.10124'
      MasterConfigurationStore: 'C:\Program Files\IVI\Data\IviConfigurationStore.xml'
                   IVIRootPath: 'C:\Program Files\IVI\'

Find the programID required to make the MATLAB Instrument Driver (MDD).

IviInfo.ProgramIDs'
ans = 

    'Agilent34980A.Agilent34980A'
    'Agilent33220.Agilent33220'
    'Agilent34945A.Agilent34945A'
    'Agilent34950A.Agilent34950A'
    'Agilent34951A.Agilent34951A'
    'Agilent34952A.Agilent34952A'
    'Agilent34959A.Agilent34959A'
    'Agilent546XX.Agilent546XX'
    'AgilentInfiniium.AgilentInfiniium'
    'AgilentN67xx.AgilentN67xx'
    'AgilentRfSigGen.AgilentRfSigGen'
    'AgilentSa.AgilentSa.4'
    'AgilentSAnBasic.AgilentSAnBasic'
    'AgilentSAnOFDMA.AgilentSAnOFDMA'
    'AgilentSAnSA.AgilentSAnSA'
    'AgilentRFPowerMeter.AgRFPM'
    'AgilentSAn.AgilentSAn'
    'AnritsuMG369X.AnritsuMG369X'
    'TekFgen.TekFgen'
    'VxiTechEX1048.VxiTechEX1048'

Create the Agilentscope.mdd using MAKEMID and the programID. The Agilentscope.mdd generated will make the IVI-COM functionality available in MATLAB. This only needs to be performed once per IVI-COM driver. The drivers are usually generated ahead of time.

makemid('Agilent546xx.Agilent546xx', 'Agilentscope.mdd');

Connect to the Instrument

Query the available VISA information.

agilentVisaInfo = instrhwinfo('visa', 'agilent')
agilentVisaInfo = 

             AdaptorDllName: [1x93 char]
          AdaptorDllVersion: 'Version 2.7.0'
                AdaptorName: 'AGILENT'
           AvailableChassis: []
       AvailableSerialPorts: {'ASRL1'}
          InstalledBoardIds: []
      ObjectConstructorName: {3x1 cell}
                SerialPorts: {'ASRL1'}
              VendorDllName: 'agvisa32.dll'
    VendorDriverDescription: 'Agilent Technologies VISA Driver'
        VendorDriverVersion: 1

Get the resource string required by the device object from the VISA ObjectConstructorName.

resourcename = agilentVisaInfo.ObjectConstructorName
resourcename = 

    'visa('agilent', 'ASRL1::INSTR');'
    'visa('agilent', 'TCPIP0::144.212.211.158::inst0::INSTR');'
    'visa('agilent', 'TCPIP0::172.31.56.121::inst0::INSTR');'

Create the device object with the VISA resource string and the MDD file.

device = icdevice('Agilentscope', 'TCPIP0::172.31.56.121::INSTR');

% Connect to the instrument.
connect(device);

Display the status of the device. The device should be open.

device
   Instrument Device Object Using Driver : Agilentscope.mdd
 
   Instrument Information
      Type:               IAgilent546XX
      Manufacturer:       Manufacturer
      Model:              Model
 
   Driver Information
      DriverType:         MATLAB IVI
      DriverName:         Agilentscope.mdd
      DriverVersion:      1.0
 
   Communication State
      Status:             open

Explore the Measurements Collection and the Measurement Items

A Measurements collection has properties and functions that work for all items it contains. A Measurement item is associated with a specific hardware asset (physical channel).

Get the list of Measurement items present in the device using the Measurement collection.

MeasurementCount = device.Measurements.Count;

% Display all analog and digital Measurement items.
% You should see four analog 16 digital Measurement items.

% Preallocate array.
MeasurementNames = {MeasurementCount};

for iLoop = 1:MeasurementCount
    MeasurementNames{iLoop, 1} = invoke(device.Measurements, 'Name', iLoop);
end
disp(MeasurementNames)
    'UserChannel1'
    'UserChannel2'
    'UserChannel3'
    'UserChannel4'
    'UserDigitalChannel0'
    'UserDigitalChannel1'
    'UserDigitalChannel2'
    'UserDigitalChannel3'
    'UserDigitalChannel4'
    'UserDigitalChannel5'
    'UserDigitalChannel6'
    'UserDigitalChannel7'
    'UserDigitalChannel8'
    'UserDigitalChannel9'
    'UserDigitalChannel10'
    'UserDigitalChannel11'
    'UserDigitalChannel12'
    'UserDigitalChannel13'
    'UserDigitalChannel14'
    'UserDigitalChannel15'

Select Channel items to use.

AnalogChannel = 1;
DigitalChannel = 5;

% Display the Name of the analog Measurement item.
AnalogMeasurementName = invoke (device.Measurements, 'Name', AnalogChannel);
disp(AnalogMeasurementName);
UserChannel1

display the Name of the digital Measurement item.

DigitalMeasurementName = invoke(device.Measurements, 'Name', DigitalChannel);
disp(DigitalMeasurementName);
UserDigitalChannel0

Acquire the Waveforms from an Analog Channel Item

Invoke AutoSetup to automatically configure the oscilloscopes settings based on the current input signals. You will hear an audible click when instrument completes the task.

invoke(device.Measurements, 'AutoSetup');

% Disable all the analog input Channel items.
device.Channel(1:4).Enabled = 'off';

% Enable a channel item.
device.Channel(1).Enabled = 'on';

% Select the Channel Name to trigger from.
device.Trigger.Source = 'UserChannel1';

% Select the voltage to trigger at.
device.Trigger.Level = 1.0;

% Select a direction to trigger at.
device.Triggeredge.Slope = 'Agilent546XXTriggerSlopePositive';

Initiate the measurement and retrieve the data.

invoke(device.Measurements, 'Initiate');

% Read the first waveform from the analog channel.
[statusval] = invoke(device.Measurements, 'Status', device);

if(int32(statusval)~=0)
    % Read the first waveform from the analog channel.
    FirstAnalogWaveform= invoke(device.Measurement(AnalogChannel), 'FetchWaveform');
else
error('instrument:demo_iviscope:Acquire','Cannot acquire waveform. Check input signal.')
end 
% Change the slope so you can see the plots intersect at the trigger point.
device.Triggeredge.Slope = 'Agilent546XXTriggerSlopeNegative';

% Initiate the reconfigured trigger.
invoke(device.Measurements, 'Initiate');

% Read the second waveform from the analog channel.
SecondAnalogWaveform = invoke(device.Measurement(AnalogChannel), 'FetchWaveform');

Plot the two analog waveforms.

plot(FirstAnalogWaveform);
hold on;
plot(SecondAnalogWaveform, 'red');
hold off;

Acquire Waveforms from Analog and Digital Channel Items

invoke(device.Measurements, 'AutoSetup');

% Disable all the analog input Channel items.
device.Channel(1:4).Enabled = 'off';
device.DigitalChannel(:).Enabled = 'off';

% Enable a channel item.
device.Channel(1).Enabled = 'on';
device.DigitalChannel(1).Enabled = 'on';

% Select the Channel Name to trigger from.
device.Trigger.Source = 'UserChannel1';

% Select the voltage to trigger at.
device.Trigger.Level = 1.0;

% Select a direction to trigger at.
device.Triggeredge.Slope = 'Agilent546XXTriggerSlopeNegative';

Initiate the measurement and retrieve the data.

invoke(device.Measurements, 'Initiate');
AnalogWaveform = invoke(device.Measurement(AnalogChannel), 'FetchWaveform');
% Read the waveform from the digital channel.
DigitalWaveform = invoke(device.Measurement(DigitalChannel), 'FetchWaveform');

Display the results.

plot(AnalogWaveform);
hold on;
plot(DigitalWaveform,'green');
hold off

Viewing Live Data

Produce a live display by retrieving data continuously from a device and repeatedly calling ReadWaveform and plotting.

invoke(device.Measurements, 'AutoSetup');
device.Channel(1:4).Enabled = 'off';
device.Channel(1).Enabled = 'on';
device.Trigger.Source = 'UserChannel1';

% To get the running waveform set the trigger level to 2.5 volts.
device.Trigger.Level = 2.5;

% Select a direction to trigger at.
device.Triggeredge.Slope = 'Agilent546XXTriggerSlopePositive';

line  = plot(1:device.Acquisition.NumberOfPointsMin);

for kLoop = 1:100

    % Call ReadWaveform to combine initiate and fetch functionality.
    AnalogData = invoke(device.Measurement(AnalogChannel), 'ReadWaveform', 2);

    % Set the new data in the line series.
    line.Ydata = AnalogData;

    % Show the figure.
    drawnow
end

Clean Up

% If you are finished with the device object, disconnect.
disconnect(device);
delete(device);
Was this topic helpful?