Instrument Control Toolbox
This example shows how to acquire digital waveform from two channels of a National Instruments® NI-SCOPE driver in the simulation mode.
Instrument Control Toolbox™ supports communication with instruments through high-level drivers. In this example you can acquire digital waveforms from a National Instruments® NI-SCOPE driver in the simulation mode.
This example requires a Microsoft® Windows® system and NI-SCOPE package 3.6 or higher. Make sure the Measurement & Automation Explorer recognizes the NI-SCOPE driver before you use this example.
instrhwinfo command to check if the NI-SCOPE software package is installed correctly. If installed correctly, NI-SCOPE is listed as one of the modules installed on the Windows machine. This example uses libraries installed with it.
driversInfo = instrhwinfo ('ivi'); disp(driversInfo.Modules');
'nidmm' 'niScope' 'nisDCPwr' 'nisDigitizer' 'nisDmm' 'nisFGen' 'nisRFSigGen' 'nisScope'
icdevice function to create an instrument object from the MDD you generated, and establish a connection to the scope using that object.
icdevice function takes two or more input arguments. The MDD file name, the resource name for the scope and optionally, device-specific parameters that can be set.
You can get the resource name for the scope from NI Measurement and Automation Explorer. For example: A resource name of
PXI1Slot6 in NI MAX would be
Device 1 would be
DAQ::Dev1. You can remove the
optionstring argument and the corresponding string parameter if you have the actual hardware.
You can establish a connection to the scope using the
ictObj = icdevice('niscope.mdd', 'DAQ::Dev1', 'optionstring', 'simulate=true'); connect(ictObj); disp(ictObj);
Instrument Device Object Using Driver : niScope Instrument Information Type: IVIInstrument Manufacturer: National Instruments Corp. Model: NI Digitizers Driver Information DriverType: MATLAB IVI DriverName: niScope DriverVersion: 1.0 Communication State Status: open
For the purpose of this example, the scope is configured using auto setup which automatically sets the vertical range, sample rate, trigger level and few other settings.
Use the MATLAB Instrument Driver Editor (midedit) to view other properties and functions that allow you to configure a device. The tool shows all the properties and functions that the NI-SCOPE software package supports.
configuration = ictObj.Configuration; invoke(configuration, 'autosetup');
ConfigureVertical function configures the most commonly configured attributes of the digitizer veritcal subsystem, such as the range, offset, coupling, probe attenuation and the channel. We will be fetching data from channels '0' and '1' and therefore configuring these channels. Refer to the NI-Scope documentation for further information
Range = 10; Offset = 0; Coupling = 1; ProbeAttenuation = 1; % Configure Channel 0 invoke(ictObj.Configurationfunctionsvertical, 'configurevertical', '0', Range, Offset, Coupling, ProbeAttenuation, true); % Configure Channel 1 invoke(ictObj.Configurationfunctionsvertical, 'configurevertical', '1', Range, Offset, Coupling, ProbeAttenuation, true);
Waveform information is a structure containing the timing information, number of samples, gain, and offset scaling factors for acquiring a waveform from the scope. Memory will be preallocated for the waveform information structure for each channel.
numChannels = 2; channelList = '0,1'; numSamples = 1024; for i = 1:numChannels waveformInfo(i).absoluteInitialX = 0; waveformInfo(i).relativeInitialX = 0; waveformInfo(i).xIncrement = 0; waveformInfo(i).actualSamples = 0; waveformInfo(i).offset = 0; waveformInfo(i).gain = 0; waveformInfo(i).reserved1 = 0; waveformInfo(i).reserved2 = 0; end
Once you configure the scope with the required settings, use an appropriate function call to acquire the waveform from channels
1. Preallocate waveformArray to store data from all requested channels. Prior to fetching data, a waveform acquisition has to be initiated. After fetching the data, extract the waveform corresponding to each channel.
waveformArray = zeros(numChannels * numSamples, 1); TimeOut = 10; % seconds invoke(ictObj.Acquisition, 'initiateacquisition'); [waveformArray, waveformInfo] = invoke(ictObj.Acquisition, 'fetch', channelList,... TimeOut, numSamples, waveformArray, waveformInfo); waveformArray = reshape(waveformArray, numSamples, numChannels);
Delete the MATLAB Instrument Object.
disconnect(ictObj); delete(ictObj); clear ictObj;