Instrument Control Toolbox
This example shows how to acquire a waveform from both channels of an Agilent Technologies® M9210A digitizer using an IVI-C driver, and display it in MATLAB. Instrument Control Toolbox™ software supports communication with instruments through IVI drivers. For a complete list of hardware supported, visit the Instrument Control Toolbox™ supported hardware page.
This example has been tested on Microsoft® Windows 7 and Windows XP Systems. Agilent IO libraries Suite and MD1 IVI driver version 188.8.131.52 need to be installed. This example requires a supported version of Microsoft Visual Studio to be installed on the system. For information on supported compilers please visit the supported compilers page. Use
mex -setup to select Visual Studio as the compiler to be used when loading the IVI Driver.
Ensure that the instrument has been configured in the VISA utility (such as Agilent Connection Expert) before you run this example.
Get Identification Information about the Instrument
INSTRHWINFO to find the instrument resource string
% Get the resource string from the Agilent VISA ObjectConstructorName and % verify it is the one used to communicate with the instrument agilentVisaInfo = instrhwinfo('visa', 'agilent'); resourceInfo = agilentVisaInfo.ObjectConstructorName
resourceInfo = 'visa('agilent', 'TCPIP0::172.31.146.123::inst0::INSTR');' 'visa('agilent', 'TCPIP0::172.31.146.27::inst0::INSTR');' 'visa('agilent', 'PXI17::10::0::INSTR');'
Verify the Driver is Installed
If the AgMD1 driver is installed, it will show up in the list of installedDrivers
IviInfo = instrhwinfo('ivi'); installedDrivers = IviInfo.Modules
installedDrivers = 'AgM933x' 'AgMD1'
Import the IVI-C Driver into MATLAB
To use the installed IVI-C driver from MATLAB, a MATLAB driver needs to be created. The MATLAB driver needs to be created only once, and should exist on the MATLAB path
% Create the MATLAB driver makemid('AgMD1', 'AgMD1.mdd', 'ivi-c');
Initialize the Driver Object and Connect to the Digitizer
Using the MATLAB driver, a device object must be created first. Using the device object, a connection is established to the digitizer from MATLAB. In this example the driver is used in simulate mode. Set Simulate=false in the initOptions variable below to run this example with an actual instrument
initOptions = 'Simulate=true, DriverSetup= Cal=0, Trace=false, model=M9210A'; visaAddress = 'PXI17::10::0::INSTR'; myDigitizer = icdevice('AgMD1.mdd', visaAddress, 'optionstring', initOptions); % Connect to the digitizer using the device object created above connect(myDigitizer);
Set Up the Digitizer to Acquire Waveforms on Channel 1 and Channel 2
After the connection is established, properties such as input impedance, number of points per record, and sampling rate need to be set, prior to acquiring the waveforms on the digitizer. The values of the enumerated datatypes used can be found in the MD1 driver documentation
% Abort present acquisition if any invoke(myDigitizer.Waveformacquisitionlowlevelacquisition, 'abort'); % Set the input impedance values of the individual channels myDigitizer.RepCapIdentifier = 'Channel1'; myDigitizer.Channel.Input_Impedance = 50; % (Ohms) myDigitizer.RepCapIdentifier = 'Channel2'; myDigitizer.Channel.Input_Impedance = 50; % (Ohms) % Set the acquisition parameters numberOfRecords = 1; ptsPerRecord = 1e4; samplingRate = 2e9; invoke(myDigitizer.Configurationacquisition, 'configureacquisition',... numberOfRecords, ptsPerRecord, samplingRate); % Set the individual channel parameters Range = 0.2; Offset = 0.0; Coupling = 1; Enabled = true; invoke(myDigitizer.Configurationchannel, 'configurechannel', 'Channel1',... Range, Offset, Coupling, Enabled); invoke(myDigitizer.Configurationchannel, 'configurechannel', 'Channel2',... Range, Offset, Coupling, Enabled); % Set the trigger source, and trigger type myDigitizer.RepCapIdentifier = 'Channel1'; myDigitizer.Trigger.Active_Trigger_Source = 'External1'; % The hex value can be found in the MD1 driver documentation AGMD1_VAL_IMMEDIATE_TRIGGER = hex2dec('000003E9'); myDigitizer.Trigger.Trigger_Type = AGMD1_VAL_IMMEDIATE_TRIGGER; % Determine the minimum amount of memory needed to fetch or read data from % the digitizer for maximum performance dataWidth = 64; numRecords = 1; offsetWithinRecord = 0; numPointsPerRecord = ptsPerRecord; arrayElements = invoke(myDigitizer.Waveformacquisitionlowlevelacquisition,... 'queryminwaveformmemory', dataWidth, numRecords,... offsetWithinRecord, numPointsPerRecord); WaveformArray = zeros(arrayElements, 1);
To acquire data from channel 1 the
READWAVEFORMREAL64 method is used. The
READWAVEFORMREAL64 method initiates acquisition of a signal on both channel 1 and channel 2, but returns the waveform for channel 1 only. Following this, to read the already acquired waveform from channel 2, the
FETCHWAVEFORMREAL64 method is used
maxTimeMilliseconds = 50; % Initiate an acquisition on all enabled channels, wait (up to % |maxTimeMilliseconds|) for the acquisition to complete, and return the % waveform for this channel [sig1, ActualPoints, FirstValidPoint, ~, ~, ~, XIncrement] = ... invoke(myDigitizer.Waveformacquisition, 'readwaveformreal64', ... 'Channel1', maxTimeMilliseconds, arrayElements, WaveformArray); sig1 = sig1(FirstValidPoint+1:FirstValidPoint+ActualPoints); % |FETCHWAVEFORMREAL64| returns a previously acquired waveform for the selected % channel. An acquisition must be made prior to calling this method. For % this case the previous call to |READWAVEFORMREAL64| has performed the waveform % acquisition already. Call this method separately for each channel [sig2, ActualPoints, FirstValidPoint, ~, ~, ~, ~] = ... invoke(myDigitizer.Waveformacquisitionlowlevelacquisition, ... 'fetchwaveformreal64', 'Channel2', arrayElements, WaveformArray); sig2 = sig2(FirstValidPoint+1:FirstValidPoint+ActualPoints);
Plot the acquired signals
SUBPLOT feature of MATLAB is used to plot the waveforms read from channel 1 and channel 2 of the digitizer
% Create the time vector using the XIncrement value returned by the % |READWAVEFORMREAL64| method t = 0:XIncrement:(length(sig1)-1)*XIncrement; figure; % Plot the channel 1 waveform subplot(2, 1, 1); plot(t, sig1); xlabel('Time (s)'); ylabel('Voltage (V)'); ylim([-.2 0.2]); title('Digitizer Channel 1'); % Plot the channel 2 waveform subplot(2, 1, 2); plot(t, sig2); xlabel('Time (s)'); ylabel('Voltage (V)'); ylim([-.2 0.2]); title('Digitizer Channel 2');
Clean Up - Delete the MD1 Device Object
After configuring the digitizer, and fetching/reading data from it, the device object needs to be closed and removed from the workspace
disconnect(myDigitizer); delete(myDigitizer); clear myDigitizer;