Using the NI-DMM .NET Class Library in IVI.NET Applications

The .NET API for NI-DMM is IVI.NET class-compliant. You can use the NI-DMM .NET API to run IVI.NET-compliant applications using DMM hardware when you have the NI-DMM driver and the .NET API for NI-DMM installed. For more information, refer to the NI Digital Multimeters Help.
Note Integrated help for IVI Foundation interfaces is not provided. You must use the IntelliSense help.

The .NET API for NI-DMM has two parts: the IVI.NET class-compliant API and the specific driver API. The following code snippet demonstrates how you can use an NI-DMM .NET specific driver API from a session obtained from an IVI.NET class-compliant API.

Note The default value of OperationMode is IviDmmMode. When configuring the session by directly setting properties for waveform acquisition, OperationMode should be set to WaveformMode.
Note The session object must be closed once, either through an IIviDmm reference or through an NIDmm reference.
  1. Create an IVI.NET class-compliant session object and acquire data, then create and use a specific driver NIDmm object to access device-specific functionality.
                VB.NET
    
    'Create an IVI DMM session. 
    Dim iviDmmSession As IIviDmm = Ivi.Driver.IviDriver.Create(Of IIviDmm)("DMM-4072", True, True)
    Dim currentRange As Double = 0.2 
    Dim currentResolutionDigits As Double = 6.5
    iviDmmSession.Configure(Ivi.Dmm.MeasurementFunction.DCCurrent, currentRange, currentResolutionDigits)
    
    'Take a reading. 
    Dim reading As Double = iviDmmSession.Measurement.Read(Ivi.Driver.PrecisionTimeSpan.FromSeconds(2))
    
    'Get an NIDmm session from the IVI DMM session and get a reading using the NIDmm session. 
    Dim sampleDmmSession As NIDmm = TryCast(iviDmmSession.GetService(GetType(NIDmm)), NIDmm)
    If sampleDmmSession IsNot Nothing Then 
        Dim waveformVoltageRange As Double = 10 
        Dim waveformPointsToRead As Integer = 100 
        Dim rate As Double = 100
        sampleDmmSession.ConfigureWaveformAcquisition(DmmMeasurementFunction.WaveformVoltage, waveformVoltageRange, rate, waveformPointsToRead)
        Dim readingArray As AnalogWaveform(Of Double) = sampleDmmSession.WaveformAcquisition.ReadWaveform(waveformPointsToRead, NationalInstruments.PrecisionTimeSpan.FromMilliseconds(10000))
    Else 
        Dim voltageRange As Double = 10, voltageResolution As Double = 0.0001 
        Dim numberOfSamples As Integer = 100
        iviDmmSession.Configure(MeasurementFunction.DCVolts, voltageRange, voltageResolution)
        iviDmmSession.Trigger.MultiPoint.SampleCount = numberOfSamples
        iviDmmSession.Trigger.Source = "Immediate" 
        Dim readingArray As Double() = iviDmmSession.Measurement.ReadMultiPoint(Ivi.Driver.PrecisionTimeSpan.FromMilliseconds(20000))
    End If
    iviDmmSession.Close()
    
                C# 
    
    // Create an IVI DMM session.
    IIviDmm iviDmmSession = Ivi.Driver.IviDriver.Create<IIviDmm>("DMM-4072", true, true);
    double currentRange = 0.2;
    double currentResolutionDigits = 6.5;
    iviDmmSession.Configure(Ivi.Dmm.MeasurementFunction.DCCurrent, currentRange, currentResolutionDigits);
    
    //Take a reading. 
    double reading = iviDmmSession.Measurement.Read(Ivi.Driver.PrecisionTimeSpan.FromSeconds(2));
    
    //Get an NIDmm session from the IVI DMM session and get a reading using the NIDmm session.
    NIDmm sampleDmmSession = iviDmmSession.GetService(typeof(NIDmm)) as NIDmm;
    if (sampleDmmSession != null)
    {
        double waveformVoltageRange = 10;
        int waveformPointsToRead = 100;
        double rate = 100;
        sampleDmmSession.ConfigureWaveformAcquisition(DmmMeasurementFunction.WaveformVoltage, waveformVoltageRange, rate, waveformPointsToRead);
        AnalogWaveform<double> readingArray = sampleDmmSession.WaveformAcquisition.ReadWaveform(waveformPointsToRead, NationalInstruments.PrecisionTimeSpan.FromMilliseconds(10000));
    }
    else
    {
        double voltageRange = 10, voltageResolution = 0.0001;
        int numberOfSamples = 100;
        iviDmmSession.Configure(MeasurementFunction.DCVolts, voltageRange, voltageResolution);
        iviDmmSession.Trigger.MultiPoint.SampleCount = numberOfSamples;
        iviDmmSession.Trigger.Source = "Immediate";
        double[] readingArray = iviDmmSession.Measurement.ReadMultiPoint(Ivi.Driver.PrecisionTimeSpan.FromMilliseconds(20000));
    }
    iviDmmSession.Close();
     
  2. Switch from an NI-DMM .NET-specific driver session to an IVI.NET DMM session in the application.
    Note Before obtaining an IIviDmm reference from an existing NIDmm that is configured for waveform acquisition, set the OperationMode to IviDmmMode.
                VB.NET
    
    Dim sampleDmmSession As New NIDmm("DMM-4072", True, True)
    Dim range As Double = 100 
    Dim resolution As Double = 6.5  
    ' Use the NIDmm session as an IVI DMM session.
    sampleDmmSession.OperationMode = DmmOperationMode.IviDmmMode
    Dim serviceProvider As IServiceProvider = TryCast(sampleDmmSession, IServiceProvider)
    Dim iviDmmSession As IIviDmm = TryCast(serviceProvider.GetService(GetType(IIviDmm)), IIviDmm)
    If iviDmmSession IsNot Nothing Then
        iviDmmSession.Configure(MeasurementFunction.DCVolts, range, resolution)
        Dim reading As Double = iviDmmSession.Measurement.Read(Ivi.Driver.PrecisionTimeSpan.FromSeconds(2))
    End If
    sampleDmmSession.Close()
    
                C#
    
    NIDmm sampleDmmSession = new NIDmm("DMM-4072", true, true);
    double range = 100;
    double resolution = 6.5;
    // Use the NIDmm session as an IVI DMM session.
    sampleDmmSession.OperationMode = DmmOperationMode.IviDmmMode;
    IServiceProvider serviceProvider = sampleDmmSession as IServiceProvider;
    IIviDmm iviDmmSession = serviceProvider.GetService(typeof(IIviDmm)) as IIviDmm;
    if (iviDmmSession != null)
    {
        iviDmmSession.Configure(MeasurementFunction.DCVolts, range, resolution);
        double reading = iviDmmSession.Measurement.Read(Ivi.Driver.PrecisionTimeSpan.FromSeconds(2));
    }
    sampleDmmSession.Close();