NI-DMM 20.0 .NET Reference

NI-DMM .NET Programming Flow

  • Updated2023-02-21
  • 3 minute(s) read

You can use the NIDmm .NET class library to initialize, configure, and read from your NI-DMM device. NI-DMM .NET, an Interchangeable Virtual Instrument (IVI)-compliant instrument driver, features a set of methods and properties that exercise the functionality of the NI-DMM hardware.

Tip Tip   For more information, refer to the Programming with NI-DMM topic in the NI Digital Multimeters Help.

The following diagram shows the basic programming flow of applications using NI-DMM.

NI-DMM Programming Workflow Diagram

Initializing a New NIDmm Session Object

For any application you write, you need to create a new NIDmm session object to establish communication with your NI-DMM device. In addition to establishing a session with the NI-DMM device in .NET, creating a new session object also sends initialization commands to set the instrument to the state necessary for the operation of the instrument driver.

Configuring the Hardware

You can configure NI-DMM .NET to acquire single point measurements, multipoint measurements, and waveform acquisitions. If you are configuring NI-DMM .NET directly by setting properties, you need to also set OperationMode. If you are configuring NI-DMM .NET using a configuration method, then you can determine the configuration method depending on the type of acquisition you use in your application. For example, DmmTrigger contains methods and properties for configuring triggers, and DmmAdvanced contains methods and properties for advanced configurations such as PowerlineFrequency and OperationMode. Set this property to WaveformMode for waveform acquisition and to IviDmmMode to work in IVI applications.

Acquiring Data

After you have configured your NI-DMM device, you can acquire data by calling Read or Initiate and Fetch. For multipoint acquisitions, you can use ReadMultiPoint or Initiate and FetchMultiPoint, and for waveform acquisitions you can use ReadWaveform or Initiate and FetchWaveform.

Closing the Session

When your acquisition is complete, close the instrument I/O session with Close or Dispose. Close destroys the session and all of its attributes and deallocates any memory resources used by the NIDmm. Dispose calls Close, then disposes the .NET object.

Note Note   If the NIDmm session in use was created using an IntPtr, then calling Close or Dispose on the session does not destroy the underlying instrument handle.

Configuring the NIDmm for Reading

The code snippet below creates and configures an NIDmm object to read DC voltage with a specific range and resolution and then closes the session.

VB.NET

Dim sampleDmmSession As New NIDmm("DMM-4072", True, True)
Dim range As Double = 100 
Dim resolution As Double = 6.5
sampleDmmSession.ConfigureMeasurementDigits(DmmMeasurementFunction.DCVolts, range, resolution)
Dim reading As Double = sampleDmmSession.Measurement.Read()
sampleDmmSession.Close()
C#

NIDmm sampleDmmSession = new NIDmm("DMM-4072", true, true);
double range = 100;
double resolution = 6.5;
sampleDmmSession.ConfigureMeasurementDigits(DmmMeasurementFunction.DCVolts, range, resolution);
double reading = sampleDmmSession.Measurement.Read();
sampleDmmSession.Close();

Configuring NI-DMM .NET for Multipoint Operations

The code snippet below demonstrates how to:

  1. Create and configure an NIDmm object to read DC voltage with a specific range and resolution;
  2. Acquire a multipoint measurement of 10 samples;
  3. Use ReadStatus to determine the number of samples acquired;
  4. Call FetchMultiPoint when a sufficient number of samples is acquired; and
  5. Call Close to end the session and deallocate any memory resources used by this NIDmm.
VB.NET

Dim sampleDmmSession As New NIDmm("DMM-4072", True, True)
Dim range As Double = 100 
Dim resolution As Double = 6.5 
Dim numberOfSamples As Integer = 10 
Dim acquisitionBacklog As Integer = 0
sampleDmmSession.ConfigureMeasurementDigits(DmmMeasurementFunction.DCVolts, range, resolution)
sampleDmmSession.Trigger.MultiPoint.SampleCount = numberOfSamples
sampleDmmSession.Trigger.Source = DmmTriggerSource.Immediate
sampleDmmSession.Measurement.Initiate()
While acquisitionBacklog < numberOfSamples 
    sampleDmmSession.Measurement.ReadStatus(acquisitionBacklog)
End While 
Dim readingArray As Double() = sampleDmmSession.Measurement.FetchMultiPoint(PrecisionTimeSpan.FromMilliseconds(2000), acquisitionBacklog)
sampleDmmSession.Close()
C#

NIDmm sampleDmmSession = new NIDmm("DMM-4072", true, true);
double range = 100;
double resolution = 6.5;
int numberOfSamples = 10;
int acquisitionBacklog=0;
sampleDmmSession.ConfigureMeasurementDigits(DmmMeasurementFunction.DCVolts, range, resolution);
sampleDmmSession.Trigger.MultiPoint.SampleCount = numberOfSamples;
sampleDmmSession.Trigger.Source = DmmTriggerSource.Immediate;
sampleDmmSession.Measurement.Initiate();
while (acquisitionBacklog < numberOfSamples) 
    sampleDmmSession.Measurement.ReadStatus(out acquisitionBacklog);
double[] readingArray = sampleDmmSession.Measurement.FetchMultiPoint(PrecisionTimeSpan.FromMilliseconds(2000), acquisitionBacklog);
sampleDmmSession.Close();

Log in to get a better experience