Option Strict Off
Option Explicit On
Module DAQ_34980A
	' following are global
	Dim msg As String ' Global error message string
	
	
	'' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    ''  © Agilent Technologies Inc. 2004, 2005, 2006
    ''  All rights reserved.
	''
	'' You have a royalty-free right to use, modify, reproduce and distribute
	'' the Sample Application Files (and/or any modified version) in any way
	'' you find useful, provided that you agree that Agilent Technologies has no
	'' warranty, obligations or liability for any Sample Application Files.
	''
	'' Agilent Technologies provides programming examples for illustration only,
	'' This sample program assumes that you are familiar with the programming
	'' language being demonstrated and the tools used to create and debug
	'' procedures. Agilent Technologies support engineers can help explain the
	'' functionality of Agilent Technologies software components and associated
	'' commands, but they will not modify these samples to provide added
	'' functionality or construct procedures to meet your specific needs.
	'' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
	
	' This program uses the Agilent 34980A IVI-COM driver.
	' The IVI-COM driver is loaded as a reference from the Project/References menu
	' When loading the references, select:
	'           IVI Agilent34980A 1.0 Type Library
	'
	' This program requires either NI Visa or
	' Visa from Agilent I/O library version M or later to be installed
	' on the computer.
	'
	' 34921A example program
	' This program assumes a 34921A MUX card in slot 1
	' This program demonstrates the use of the 34921A to create scans with a
	' number of functions and channels
    Sub main_34980A(ByVal myAddress As String)
        Dim numberSweeps As Integer
        Dim sweep As Short
        Dim numberChannels As Integer
        Dim standardInitOptions As String
        Dim driverSetupOptions As String

        On Error GoTo ErrorHandler
        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Setup IVI-defined initialization options
        standardInitOptions = "QueryInstrStatus=true, Simulate=false"

        ' Setup driver-specific initialization options
        driverSetupOptions = "DriverSetup=Model=34980A"

        'Open a session to the mainframe
        Dim host As New Agilent.Agilent34980A.Interop.Agilent34980A

        ' Send a reset when we open the instrument
        host.Initialize(myAddress, False, True, standardInitOptions & "," & driverSetupOptions)

        ' Set Timeout to 20 seconds to allow for the scan to complete
        host.System.TimeoutMilliseconds = 20000

        Configure_34980A(host)
        SetScan_34980A(host, numberSweeps, numberChannels)

        ' This will read the data of all the sweeps
        Dim Readings(numberSweeps - 1, numberChannels - 1) As Object
        ReadData_34980A(host)
        host.Close()
        Exit Sub

ErrorHandler:
        System.Diagnostics.Debug.WriteLine("Error: " & Err.Description)
        host.Close()
    End Sub
    Sub Configure_34980A(ByRef Instrument As Agilent.Agilent34980A.Interop.Agilent34980A)
        ' This program assumes a 34921A MUX card in SLOT 1
        ' Configure all channels in channel list

        On Error GoTo ErrorHandler
        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Configure Channel 1001   Temp. Thermist. 5k  °C
        Instrument.Temperature.Thermistor.Configure("1001", Agilent.Agilent34980A.Interop.Agilent34980AResolutionEnum.Agilent34980AResolutionDefault, Agilent.Agilent34980A.Interop.Agilent34980AThermistorEnum.Agilent34980AThermistor5000)
        ' Configure Channels 1004:1005  Volts DC    10 V    5 ½ digits
        Instrument.Voltage.DCVoltage.Configure("1004,1005", 10.0#, Agilent.Agilent34980A.Interop.Agilent34980AResolutionEnum.Agilent34980AResolutionDefault)
        ' Channels 1006   Resistance  10 Mohm 5 ½ digits
        ' Channels 1007   Resistance  10 Mohm 5 ½ digits
        Instrument.Resistance.Configure("1006,1007", 10000000.0#, Agilent.Agilent34980A.Interop.Agilent34980AResolutionEnum.Agilent34980AResolutionDefault)
        ' Channel 1014   Resistance  100 ohm 5 ½ digits
        Instrument.Resistance.Configure("1014", 100.0#, Agilent.Agilent34980A.Interop.Agilent34980AResolutionEnum.Agilent34980AResolutionDefault)
        ' Channels 1015   4w Resistance   100 ohm 4 ½ digits
        Instrument.Resistance.Configure("1015", 100.0#, Agilent.Agilent34980A.Interop.Agilent34980AResolutionEnum.Agilent34980AResolutionLeast)
        Exit Sub

        ''''''''''''''''''''''''''''''''''''''''''''''''''
ErrorHandler:
        If Err.Number <> 0 Then
            msg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source & Err.Description

            System.Diagnostics.Debug.WriteLine(msg)

        End If

    End Sub
    Sub SetScan_34980A(ByRef Instrument As Agilent.Agilent34980A.Interop.Agilent34980A, ByRef numberSweeps As Integer, ByRef numberChannels As Integer)

        ' Set up the scanning parameters
        numberSweeps = 2

        ' Set up the scan List
        ' This is a list of all channels in Configure_34980A
        Instrument.Scan.ScanList = "1001,1002:1005,1006,1007,1014,1015"

        ' Configure the trigger source, set number of triggers 2
        ' Set trigger source timer, and time between triggers as 2 seconds
        'Instrument.Trigger.Configure Agilent34980ATriggerSourceTimer, numberSweeps, 2, 1
        Instrument.Trigger.Source = Agilent.Agilent34980A.Interop.Agilent34980ATriggerSourceEnum.Agilent34980ATriggerSourceTimer
        Instrument.Trigger.Count = 2
        Instrument.Trigger.Timer = 2

        'Read the number of channels on scan list
        numberChannels = Instrument.Scan.ScanSize

        ' Arm the trigger with initiate, this starts the measurement
        Instrument.Measurement.Initiate()

    End Sub

    Sub ReadData_34980A(ByRef Instrument As Agilent.Agilent34980A.Interop.Agilent34980A)
        ' Reads the data all at once into an array
        ' See the manual for alternative ways to read the data
        ' using Read?, R?, Data:Remove? and Measure?
        Dim rowMax As Integer
        Dim row As Integer
        Dim strReadArray() As String
        Dim i As Integer

        ' Wait up to 30 seconds for the scan to complete
        Instrument.System.WaitForOperationComplete(30000)

        'Enable channel number and units to be returned in data
        Instrument.Measurement.DataFormat.ChannelEnable = True
        Instrument.Measurement.DataFormat.UnitEnable = True

        'Retrieve the formatted data from the instrument
        strReadArray = VB6.CopyArray(Instrument.Measurement.Fetch)

        rowMax = UBound(strReadArray)

        ' Print the data to the text box and the Immediate window
        frmIviCom.DefInstance.txtReadings.Text = ""
        For row = 0 To rowMax
            frmIviCom.DefInstance.txtReadings.SelectedText = strReadArray(row) & vbCrLf
            System.Diagnostics.Debug.WriteLine(vbCrLf)
        Next row

    End Sub
End Module