AnsweredAssumed Answered

Agilent 33500A/33500B function gen ASCII ARB example program

Question asked by lhornburg Employee on Aug 30, 2012
Latest reply on Aug 30, 2012 by lhornburg

    '    Copyright © 2010 Agilent Technologies Inc. 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 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 support engineers can help explain the
    ' functionality of Agilent 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 sample program is intended to use with Microsoft Visual studio 6.0
    'and Agilent Visa Object library.
    'Sample program execution requires VISA library installation as pre requisites.
    'Add below libraries in project reference in Project\reference menu prior to execution of sample 'program:
    'VISA COM 3.0 Type Library, Location: \VisaCom\GlobMgr.dll
    'VISA COM 488.2 Formatted I/O 1.0, Location: \VisaCom\BasFrmIO.dll
    'VISA COM Resource Manager 1.0, Location: \bin\AgtRM.dll
' ****************************************************************************

' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'AsciiArb is a sample program that demonstrates how to download an arbitrary waveform
'into instrument volatile memory and play back the same with the configuration below:
'This arb generates a 4000 point pulse waveform, of which the first 200 points define a
'positive pulse from 0 volts to the maximum defined voltage amplitude.
'Wave Shape: Arb
'Frequency:  40 KSa/Sec
'Amplitude:  2 Volt Peak to Peak
'Offset:     0 Volt
'Output Impedance:   50 Ohm
'Channel1 Output: Enabled
'Caution: All un-saved data present in volatile memory will be erased.
'Save information before proceeding to this example program.
' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Private Sub Command1_Click()

    Dim io_mgr As VisaComLib.ResourceManager
    Dim mFio As VisaComLib.FormattedIO488
    Set io_mgr = New AgilentRMLib.SRMCls
    Set mFio = New FormattedIO488
    Set mFio.IO = io_mgr.Open(Text1.Text, NO_LOCK, 2000, "")
    Dim Waveform() As String
    Dim I As Integer
    Dim DataStr As String
    ReDim Waveform(1 To 4000)
    On Error GoTo MyError

    'Compute waveform
    Text2.Text = ""
    Text2.Text = Text2.Text & "Computing Waveform..." & vbCrLf

    For I = 1 To 5
        Waveform(I) = Str$((I - 1) / 5)         ' Set rise time (5 points)
    Next I

    For I = 6 To 205
        Waveform(I) = "1"                       ' Set pulse width (200 points)
    Next I

    For I = 206 To 210
        Waveform(I) = Str$((210 - I) / 5)       ' Set fall time (5 points)
    Next I

    For I = 211 To 4000
        Waveform(I) = "0"                       ' Set remaining points to zero
    Next I

    DataStr = Join(Waveform, ",")               ' Create string from data array

    With mFio
        'Clear and reset instrument & increase timeout of Visa Connection to 40 Seconds for downloading long waveform
        .WriteString "*CLS"
        .WriteString "*RST"
        .IO.Timeout = 40000
        Sleep 1000
        Call WaitForOPC(mFio)
         '    * Clearing Volatile memory.
         '    * Cautions: All un-saved data present in volatile memory will be erased.
         '    * Save information before proceeding to this example program.
        .WriteString "DATA:VOLatile:CLEar"
    End With
        'Downloading Waveform.
        Text2.SelStart = Len(Text2.Text)
        Text2.SelText = "Downloading Waveform..." & vbCrLf
    With mFio
        .WriteString "SOURce1:DATA:ARBitrary TestArb," & DataStr
    End With
    Call WaitForOPC(mFio)
    Text2.Text = Text2.Text & "Download Complete" & vbCrLf
    With mFio
        'Send Command to set the desired configuration
     .WriteString "SOURce1:FUNCtion:ARBitrary TestArb" ' set current arb waveform to defined arb pulse
        .WriteString "SOURce1:FUNCtion ARB" ' turn on arb function
        .WriteString "SOURCE1:VOLT 2" ' set max waveform amplitude to 2 Vpp
        .WriteString "SOURCE1:VOLT:OFFSET 0" ' set offset to 0 V
        .WriteString "OUTPUT1:LOAD 50" ' set output load to 50 ohms
        .WriteString "SOURCE1:FUNCtion:ARB:SRATe 40000" ' set sample rate

        'Enable output.
        .WriteString "OUTPUT1 ON" 'turn on channel 1 output
        Sleep 1000
    End With
    Text2.Text = Text2.Text & "Arb Wave output set on Channel1" & vbCrLf
Exit Sub

    Text2 = Err.Description
    Resume Next
End Sub

Private Sub Form_Load()

    Text2.Text = ""
End Sub

Private Function WaitForOPC(mFio As VisaComLib.FormattedIO488)
        Dim strResult As String
        With mFio
            .WriteString "*OPC?"
            strResult = .ReadString()
        End With
        If (InStr(strResult, "1") > 0) Then
            Exit Do
        End If
End Function