AnsweredAssumed Answered

N6700A capturing digitized data from N6762A module

Question asked by david001 on Jul 5, 2012
Latest reply on Jul 6, 2012 by david001
Hello,

I cannot figure out how to accurately capture the simultaneous digitized current and voltage data.  I am using the N6762A in slot 2 & 4.  I've attached a 50 ohm load to the outputs and can get the N6762A to output a constant current that I desired.  Whenever I try to capture the digitized data, it seems as if I have something wrong with when it triggers or when the buffer starts collecting data.  I am using VB.net but have a step voltage example in vb6 using the digitizer.  I am not very familar with vb6 but I will attach my code and the digitizer example provided by agilent.  My code goes back and forth sending SCPI and using the IVI driver when I can.  Any advice would be greatly appreciated.

''I am using the IVI driver for the AgilentN67XX


Imports System.IO

Public Class Hardware
'Declaring Agilent PS
    Dim PS1 As New AgilentN67XX.Driver("N6701A", True, False, "1")
    Dim PS2 As New AgilentN67XX.Driver("N6701A", True, False, "2")
    Dim PS3 As New AgilentN67XX.Driver("N6701A", True, False, "3")
    Dim PS4 As New AgilentN67XX.Driver("N6701A", True, False, "4")

'For Fetcharray command
Public readingvolt3(4096) As Double
Public readingamp3(4096) As Double
Public readingvolt4(4096) As Double
Public readingamp4(4096) As Double
Public numReadVolt As Integer
Public numReadAmp As Integer
Public numReadVolt2 As Integer
Public numReadAmp2 As Integer




'From VB6 programming example
Const WTG_MEAS = 8
Const WTG_TRANS = 16
'for readinstdata statement
Dim Reading As New System.Text.StringBuilder(1024)
Dim Reading1 As New System.Text.StringBuilder(1024)
Dim Reading2 As New System.Text.StringBuilder(1024)
Dim numRead As Integer
Dim numRead1 As Integer
Dim numRead2 As Integer


Public LOGFILEPATH As String = "C:\Users\developer\Desktop\voltcurrent.txt"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PS2.reset()

'Setting up the sweep offset, sample points, & time intervals
PS2.ConfigureMeasurement(AgilentN67XX.agn6700Constants.MeasureVoltage, 0, 4096, 0.00005)
PS2.ConfigureMeasurement(AgilentN67XX.agn6700Constants.MeasureCurrent, 0, 4096, 0.00005)
PS4.ConfigureMeasurement(AgilentN67XX.agn6700Constants.MeasureVoltage, 0, 4096, 0.00005)
PS4.ConfigureMeasurement(AgilentN67XX.agn6700Constants.MeasureCurrent, 0, 4096, 0.00005)

' coupling PS2 & PS4 so they come on at the same time

PS2.WriteInstrData("OUTP:COUP ON")
PS2.WriteInstrData("OUTP:COUP:CHAN 2,4")
'setting overvoltage protection @15V
PS2.ConfigureOVP(True, 15)
PS2.WriteInstrData("CURR:PROT:STAT ON,(@2)")
PS4.ConfigureOVP(True, 15)
PS4.WriteInstrData("CURR:PROT:STAT ON,(@4)")


'limiting the output current to .3A
PS2.ConfigureCurrentLimit(AgilentN67XX.agn6700Constants.CurrentRegulate, 0.3)
PS2.ConfigureVoltageLevel(15)
PS4.ConfigureCurrentLimit(AgilentN67XX.agn6700Constants.CurrentRegulate, 0.3)
PS4.ConfigureVoltageLevel(15)

'setting the preferred mode so I can get constant current (CC) source
PS2.WriteInstrData("OUTP:PMOD CURR,(@2)")
PS4.WriteInstrData("OUTP:PMOD CURR,(@4)")

' setting up a current output list
PS2.ConfigureTriggeredCurrentMode(AgilentN67XX.agn6700Constants.TriggerCurrentModeList)
PS4.ConfigureTriggeredCurrentMode(AgilentN67XX.agn6700Constants.TriggerCurrentModeList)
PS2.ConfigureCurrentList(4, {0.3, 0.001, 0.3, 0.001})
PS4.ConfigureCurrentList(5, {0.001, 0.3, 0.001, 0.3, 0.001})
PS2.ConfigureDwellList(4, {0.03, 0.028, 0.03, 0.028})
PS4.ConfigureDwellList(5, {0.03, 0.03, 0.03, 0.008, 0.02})
PS2.ConfigureList(1, AgilentN67XX.agn6700Constants.ListStepAuto, False)
PS4.ConfigureList(1, AgilentN67XX.agn6700Constants.ListStepAuto, False)

'then will turn on PS2 and PS4 at the same time
PS2.ConfigureOutputEnabled(True)

PS2.WriteInstrData("*OPC?")
'I am having a problem getting the line below to work correctly.  parameters are: Number of bytes to read, Read buffer, Num_bytes_read
OPC = PS2.ReadInstrData(1024, Reading, numRead)

'Initiating triggers
PS2.WriteInstrData("TRIG:TRAN:SOUR BUS,(@2)")
PS4.WriteInstrData("TRIG:TRAN:SOUR BUS,(@4)")
PS2.WriteInstrData("TRIG:ACQ:SOUR BUS,(@2)")
PS4.WriteInstrData("TRIG:ACQ:SOUR BUS,(@4)")
'setting up a loop to make sure the initiate has completed before sending a trigger per manual
Do

        PS2.WriteInstrData("STAT:OPER:COND? (@2)")
        Status = PS2.ReadInstrData(1024, Reading1, numRead1)
        PS4.WriteInstrData("STAT:OPER:COND?(@4)")
     Status2 = PS4.ReadinstrData(1024, Reading2, numread2)
        


     Loop Until (Status And Status2 And (WTG_MEAS + WTG_TRANS)) = (WTG_MEAS + WTG_TRANS)

        
'Send trigger
PS2.WriteInstrData("*TRG")
PS4.WriteInstrData("*TRG")

'fetching the current and voltage on PS2 and PS4 that was digitized
PS2.FetchArray(AgilentN67XX.agn6700Constants.MeasureVoltage, 4096, readingvolt3, numReadVolt)
PS2.FetchArray(AgilentN67XX.agn6700Constants.MeasureCurrent, 4096, readingamp3, numReadAmp)
PS4.FetchArray(AgilentN67XX.agn6700Constants.MeasureVoltage, 4096, readingvolt4, numReadVolt2)
PS4.FetchArray(AgilentN67XX.agn6700Constants.MeasureCurrent, 4096, readingamp4, numReadAmp2)
'attempting to capture digitized data into a textfile
WritePSdataToLogFile(readingvolt3, readingamp3, readingvolt4, readingamp4)
    End Sub

Public Sub WritePSdataToLogFile(ByVal readingvolt3() As Double, ByVal readingamp3() As Double, ByVal readingvolt4() As Double, ByVal readingamp4() As Double)
        Dim SW As StreamWriter
        Dim LineData As String
        Dim i As Long
        SW = New StreamWriter(LOGFILEPATH, True)


        
        For i = 0 To 4096

            LineData = readingvolt3(i) & "," & readingamp3(i) & "," & readingvolt4(i) & "," & readingamp4(i)
            SW.WriteLine(LineData)
        Next

        SW.Close()
        SW = Nothing
    End Sub
End Class


Agilents example in vb6


Sub digitizer_programming_example()

    Dim IDN As String

    Dim GPIBaddress As String

    Dim ErrString As String

    Dim channel As String

    Dim measPoints As Long

    Dim measOffset As Long

    Dim VoltSetting As Double

    Dim finalVoltage As Double

    Dim timeInterval As Double

    Dim VoltPoints() As Variant

    Dim i As Long

    Const WTG_MEAS = 8

    Const WTG_TRANS = 16

    'These variables are necessary to initialize the VISA COM.

    Dim ioMgr As AgilentRMLib.SRMCls

    Dim Instrument As VisaComLib.FormattedIO488

    ' The following command line provides the program with the VISA name of the

    ' interface that it will communicate with. It is currently set to use GPIB.

    GPIBaddress = "GPIB0::5::INSTR"

    ' Use the following line instead for LAN communication

    ' TCPIPaddress="TCPIP0::141.25.36.214"

    ' Use the following line instead for USB communication

    ' USBaddress = "USB0::2391::1799::US00000002"

    ' Initialize the VISA COM communication

    Set ioMgr = New AgilentRMLib.SRMCls

    Set Instrument = New VisaComLib.FormattedIO488

    Set Instrument.IO = ioMgr.Open(GPIBaddress)

    ' This controls the number of points the measurement system measures

    measPoints = 100

    ' This controls the number of points to offset the measurement (positive for

    ' forward, negative for reverse)

    measOffset = 0

    ' This sets the time between points

    timeInterval = 0.0025

    ' This controls the voltage

    VoltSetting = 5

    ' This is the final voltage that will be triggered

    finalVoltage = 10

    ' This variable can be changed to program any channel in the mainframe

    channel = "(@1)"                          ' channel 1

    With Instrument

        ' Send a power reset to the instrument

        .WriteString "*RST"

        ' Query the instrument for the IDN string

        .WriteString "*IDN?"

        IDN = .ReadString

        ' Put the Voltage into step mode which causes it to transition from one

        ' voltage to another upon receiving a trigger

        .WriteString "VOLT:MODE STEP," & channel

        ' Set the voltage

        .WriteString "VOLT" & Str$(VoltSetting) & "," & channel

        ' Go to final value

        .WriteString "VOLT:TRIG" & Str$(finalVoltage) & "," & channel

        ' Turn the output on

        .WriteString "OUTP ON," & channel

        ' Wait for output to turn on.

        .WriteString "*OPC?"

        .ReadString

        ' Set the bus as the transient trigger source

        .WriteString "TRIG:TRAN:SOUR BUS," & channel

        ' Set the number of points for the measurement system to use as an offset

        .WriteString "SENS:SWE:OFFS:POIN" & Str$(measOffset) & "," & channel

        ' Set the number of points that the measurement system uses

        .WriteString "SENS:SWE:POIN" & Str$(measPoints) & "," & channel

        ' Set the time interval between points

        .WriteString "SENS:SWE:TINT" & Str$(timeInterval) & "," & channel

        ' Set the measurement trigger source

        .WriteString "TRIG:ACQ:SOUR BUS," & channel

        ' Initiate the measurement trigger system

        .WriteString "INIT:ACQ " & channel

        ' Initiate the transient trigger system

        .WriteString "INIT:TRAN " & channel

        ' Wait for INITiate commands to complete

        Do

            .WriteString "STAT:OPER:COND? " & channel

            Status = .ReadString

        Loop Until (Status And (WTG_MEAS + WTG_TRANS)) = (WTG_MEAS + WTG_TRANS)

        ' Trigger the unit

        .WriteString "*TRG"

        ' Read back the voltage points

        .WriteString "FETC:ARR:VOLT? " & channel

        VoltPoints = .ReadList

        

        ' Print the first 10 voltage points

        For i = 0 To 9

            Debug.Print i, VoltPoints(i)

        Next i

        ' Check instrument for any errors

        .WriteString "Syst:err?"

        ErrString = .ReadString

        ' give message if there is an error

        If Val(ErrString) Then

            MsgBox "Error in instrument!" & vbCrLf & ErrString

        End If

    End With

End Sub  

Outcomes