Basic Usage

You can use the NI-DCPower .NET class library to initialize, configure, initiate, run, and close a session on your NI-DCPower device. The NI-DCPower .NET API is an Interchangeable Virtual Instrument (IVI)-compliant instrument driver that features a set of methods and properties that exercise the functionality of the NI-DCPower hardware.

  1. Initialization—Use a constructor to create a new instance of the NIDCPower class. You must create an instance of this class before you can call into the underlying NI-DCPower driver.
    VB.NET
    
    Dim dcPowerSession As New NIDCPower("resourceName", "0", False) ' Initialize.
    
    Visual C#
    
    NIDCPower dcPowerSession = new NIDCPower("resourceName", "0", false); // Initialize.
    
  2. Configuration—Use the NIDCPower object to access various subobjects and to configure the NI-DCPower driver directly or indirectly. You can use the Outputs collection subobject to configure channel-specific properties.
    VB.NET
    
    Dim dcPowerSession As New NIDCPower("resourceName", "0", False)
    dcPowerSession.Source.Mode = DCPowerSourceMode.SinglePoint
    dcPowerSession.Outputs("0").Source.Output.Function = DCPowerSourceOutputFunction.DCCurrent
    dcPowerSession.Outputs("0").Measurement.Sense = DCPowerMeasurementSense.Local
    dcPowerSession.Outputs("0").Source.Current.CurrentLevel = 0.02
    dcPowerSession.Measurement.Configuration.MeasureWhen = DCPowerMeasurementWhen.OnDemand
    
    
    Visual C#
    
    NIDCPower dcPowerSession = new NIDCPower("resourceName", "0", false);
    dcPowerSession.Source.Mode = DCPowerSourceMode.SinglePoint;
    dcPowerSession.Outputs["0"].Source.Output.Function = DCPowerSourceOutputFunction.DCCurrent;
    dcPowerSession.Outputs["0"].Measurement.Sense = DCPowerMeasurementSense.Local;
    dcPowerSession.Outputs["0"].Source.Current.CurrentLevel = 0.02;
    dcPowerSession.Measurement.Configuration.MeasureWhen = DCPowerMeasurementWhen.OnDemand;
    
    
  3. Initiate—The NI-DCPower instrument starts sourcing or measuring, causing the NI-DCPower session to enter the running state.
    VB.NET
    
    dcPowerSession.Control.Initiate()
    
    Visual C#
    
    dcPowerSession.Control.Initiate();
    
  4. Running State—In the running state, you can take measurements, fetch buffered measurements, query the output state, or query the instrument state.
    VB.NET
    
    Dim result As DCPowerMeasureResult = dcPowerSession.Measurement.Measure("0") ' Measure the voltage and current. 
    Dim inCompliance As Boolean = dcPowerSession.Measurement.QueryInCompliance("0") ' Determine if the output is in compliance.
    
    
    Visual C#
    
    DCPowerMeasureResult result = dcPowerSession.Measurement.Measure("0"); // Measure the voltage and current. 
    bool inCompliance = dcPowerSession.Measurement.QueryInCompliance("0"); // Determine if the output is in compliance.
    
    
  5. Close—Close the session to the instrument and free unmanaged resources that are held by the session. You can close the session with Close or Dispose.
    VB.NET
    
        dcPowerSession.Close()
        or
        dcPowerSession.Dispose()
        or 
        Using dcPowerSession As New NIDCPower("resourceName", "0", false)
    ' User code goes here. 
        End Using
    
    
    Visual C#
    
    dcPowerSession.Close();
    or
    dcPowerSession.Dispose();
    or
    using (NIDCPower dcPowerSession = new NIDCPower("resourceName", "0", false))
    {
        // User code goes here.
    }
    
    

Refer to the Programming States topic in the NI DC Power Supplies and SMUs Help for information about the specific NI-DCPower software states.