Generate DC Voltage Using 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.
Requirements
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');
disp(driversInfo.Modules');
{'nidcpower' }
{'nidmm' }
{'niFgen' }
{'nisACPwr' }
{'niScope' }
{'nisCounter' }
{'nisDCPwr' }
{'nisDigitizer' }
{'nisDmm' }
{'nisDownconverter'}
{'nisFGen' }
{'nisPwrMeter' }
{'nisRFSigGen' }
{'nisScope' }
{'nisSpecAn' }
{'nisSwtch' }
{'nisUpconverter' }
{'niSwitch' }
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 optional device-specific parameters.
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'); connect(ictObj); disp(ictObj);
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);
disp(voltageDisplay);
Voltage : 6 v
Clear the Connection
Disconnect from and delete the MATLAB Instrument Object.
disconnect(ictObj);
delete(ictObj);
clear ictObj;