Instrument Control Toolbox

Source DC voltage through NI-DCPOWER MATLAB Instrument Driver in Simulation Mode

This example shows how to generate DC voltage from a National Instruments® NI-DCPOWER driver in the simulation mode.


Instrument Control Toolbox™ supports communication with instruments through high-level drivers. In this example you can read voltage from a National Instruments® NI-DCPOWER driver in the simulation mode.


This example requires a Microsoft® Windows® system and NI-DCPOWER package 1.7 or higher.

Verify NI-DCPOWER Installation

Use the instrhwinfo command to check if the NI-DCPOWER software package is installed correctly. If installed correctly, NI-DCPOWER is listed as one of the modules installed on the Windows machine. This example uses libraries installed with it.

driversInfo = instrhwinfo ('ivi');

Create a MATLAB Instrument object

Use the icdevice function to create an instrument object from the MDD which was part of the NI-DCPOWER support package, and establish a connection to the DCPOWER using that object.

The icdevice function takes two or more input arguments. The MDD file name, the resource name for the DCPOWER, and optionally, device-specific parameters that can be set.

You can get the resource name for the DCPOWER from NI Measurement and Automation Explorer. For example: A resource name of PXI1Slot1 in NI MAX would be DAQ::PXI1Slot1 and 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 DCPOWER using the connect command.

ictObj = icdevice('nidcpower.mdd', 'DAQ::PXI1Slot1', 'optionstring','simulate=true');
   Instrument Device Object Using Driver : niDCPower
   Instrument Information
      Type:               IVIInstrument
      Manufacturer:       National Instruments Corp.
      Model:              National Instruments DC Power Supplies
   Driver Information
      DriverType:         MATLAB IVI
      DriverName:         niDCPower
      DriverVersion:      1.0
   Communication State
      Status:             open

Configure the DCPOWER

For the purpose of this example, the DCPOWER is configured as

* Channel: 0
* Source Mode: Single Point
* Output Function: DC Voltage
* Voltage Level: 6V

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-DCPOWER software package supports.

channel = '0';
src = get(ictObj, 'source');

% Configure the Source mode to Single Point
sourceMode = 1020;
invoke(src, 'configuresourcemode', sourceMode);

% Set the output function to DC Voltage
outputFunction = 1006;
invoke(src, 'configureoutputfunction', channel, outputFunction);

srcDCVoltage = get(ictObj, 'sourcedcvoltage');

% Configure the Voltage level, in volts, for the output channel generation
voltageLevel = 6;
invoke(srcDCVoltage, 'configurevoltagelevel', channel, voltageLevel);

Start generation and acquisition

% Initiate the device to start generation
control = get(ictObj, 'control');
invoke(control, 'initiate');

% Measure voltage
measurementType = 1;
measure = get(ictObj, 'measure');
volts = invoke(measure, 'measure', channel, measurementType);

Display the read voltage

voltageDisplay = sprintf('Voltage : %d v', volts);
Voltage : 6 v

Clean up

Delete the MATLAB Instrument Object.

clear ictObj;