The IVI-C wrappers provide an interface to MATLAB® for instruments running on IVI-C class-compliant drivers.
This documentation example uses a specific instrument, a Keysight™ MSO6104A oscilloscope. This feature works with any IVI-C class-compliant instrument. You can follow the basic steps, using your particular instrument if the device is IVI-C class-compliant.
To use the wrapper you must have the following software installed.
VISA shared components
The following example uses Keysight VISA, but you can use any version of VISA.
National Instruments™ compliance package NICP 4.1
Your instrument driver
You can use
instrhwinfo to confirm that these
software modules are installed.
% Check that the software is properly installed. instrhwinfo('ivi')
When using IVI-C or VXIplug&play drivers, executing your code will generate additional files in the folder specified by executing the following code at the MATLAB prompt:
On all supported platforms, a file with the name
MATLABPrototypeFor<driverName>.m is generated, where
<driverName> the name of the IVI-C or
VXIplug&play driver. With 64-bit MATLAB on Windows, a second file by the name
<driverName>_thunk_pcwin64.dll is generated. When creating your
deployed application or shared library, manually include these generated files. For more
information on including additional files refer to the MATLAB Compiler documentation.
This example shows the general workflow to use with an IVI-C class-compliant device. This example uses a specific instrument, a Keysight MSO6104A oscilloscope. This feature works with any IVI-C class-compliant instrument. You can follow the basic steps using your particular instrument if it is IVI-C class-compliant.
Ensure all necessary software is installed. See Prerequisites for the list.
Ensure that your instrument is recognized by the VISA utility. In this case, open Keysight Connectivity Expert and make sure it recognizes the oscilloscope.
Set up the logical name using the Configuration Store. The VISA resource string shown in this code was acquired from the VISA utility in step 2.
% Construct a configStore. configStore = iviconfigurationstore; % Set up the hardware asset called myScopeHWAsset, and resource description TCPIP0::a-m6104a-004598::INSTR. add(configStore, 'HardwareAsset', 'myScopeHWAsset', 'TCPIP0::a-m6104a-004598::INSTR'); % Add a driver session called myScopeSession, and use the asset created in the step above. Ag546XX is the Agilent driver version. add(configStore, 'DriverSession', 'myScopeSession', 'Ag546XX', 'myScopeHWAsset'); % Add a logical name to the configStore called myScope and driver session called myScopeSession. add(configStore, 'LogicalName', 'myScope', 'myScopeSession'); % Save the changes to the IVI configuration store data file. commit(configStore); % You can verify that the steps you just performed worked. logicalNameInfo = instrhwinfo('ivi', 'myscope')
For more information about the configuration store, see IVI Configuration Store.
Create an instance of the scope.
% Instantiate an instance of the scope. ivicScope = instrument.ivic.IviScope();
Connect to the instrument.
% Open the hardware session. ivicScope.init('myScope', true, true);
Communicate with the instrument. For example, read a waveform.
% Use the AutoSetup method to automatically set up the oscilloscope. ivicScope.Configuration.AutoSetup(); % Create a record length variable. recordLength = ivicScope.Acquisition.Horizontal_Record_Length; % Preallocate buffer to store the data read from the scope. waveformArray = zeros(1, recordLength); % Read a waveform with channel name set to channel1 and timeout to 1000. [waveformArray,actualPoints,initiaX,xIncrement] = ivicScope.WaveformAcquisition. ReadWaveform('channel1', recordLength, 1000, waveformArray); % Plot the waveform and assign labels for the plot. plot(waveformArray); xlabel('Samples'); ylabel('Voltage');
After configuring the instrument and retrieving its data, close the session and remove it from the workspace.
ivicScope.close(); clear ivicScope;
You can also use the IVI-C Wrappers functionality from the Test & Measurement Tool. View the IVI-C nodes by setting a preference in MATLAB.
In MATLAB, on the Home tab, in the Environment section, click Preferences. Then select Instrument Control in the Preferences dialog box.
Select the Show IVI Instruments in TMTool option in the IVI Instruments section.
If you do not have the required software installed, you will get a message indicating that. See Prerequisites for the list of required software.
Start the Test & Measurement Tool (using the
and the new IVI Instruments node appears under Instrument
For information on using it in the Test & Measurement Tool, see the Help within the tool by selecting the IVI Instruments node in the tree once it is visible after setting the MATLAB preference.