Waiting for Measurement End (SRQ)

Other topics about Sample Programs

Overview

This sample program demonstrates how to use an SRQ to detect the end of measurement.

The sample program sets up the trigger system, configures the instrument to properly generate an SRQ, and then triggers the instrument. When the instrument has generated an SRQ that indicates the end of measurement.

See Waiting for the End of Measurement for this programming.

Sample Program in Excel VBA

Option Explicit

Implements VisaComLib.IEventHandler

    '*** The variables of the resource manager and the instrument I/O are declared

    Dim ioMgr As VisaComLib.ResourceManager

    Dim Ena As VisaComLib.FormattedIO488

    Dim SRQ As VisaComLib.IEventManager

 

Sub IEventHandler_HandleEvent( _

        ByVal Ena As VisaComLib.IEventManager, _

        ByVal SRQevent As VisaComLib.IEvent, _

        ByVal userHandle As Long)    ' Once the SRQ is detected, then get the data

    Call ReadData

End Sub

 

Sub UserForm_Initialize()

    Set ioMgr = New VisaComLib.ResourceManager

    Set Ena = New VisaComLib.FormattedIO488

  

    '*** Open the instrument & Sets the GPIB address

    Set Ena.IO = ioMgr.Open("GPIB0::17::INSTR")

    Ena.IO.timeout = 100000   ' TimeOut time should be greater than the measurement time.

    

    '*** Variable declaration. Select the code

    Dim i As Double, dummy As Integer

    Range("A5:B100").Clear

    

    Set SRQ = Ena.IO

    SRQ.InstallHandler EVENT_SERVICE_REQ, Me

    SRQ.EnableEvent EVENT_SERVICE_REQ, EVENT_HNDLR

    

    '* Aborts the trigger system and sets the trigger source to the internal trigger.

    Ena.WriteString "*CLS", True

    Ena.WriteString ":ABOR", True

    Ena.WriteString ":INIT:CONT ON", True

    

    Ena.WriteString ":TRIG:SOUR BUS", True

    

    '* Sets the positive transition filter to 0 and the negative transition filter to 1

    '*  so that the operation status event register at bit 4 is set to 1 only when the

    '*  operation status condition register at bit 4 is changed from 1 to 0.

    Ena.WriteString ":STAT:OPER:PTR 0", True

    Ena.WriteString ":STAT:OPER:NTR 16", True

    

    '* Enables bit 4 in the operation status event register and bit 8 in the status byte register.

    Ena.WriteString ":STAT:OPER:ENAB 16", True

    Ena.WriteString "*SRE 128", True

    

    '* Clears the operation status event register and the status byte register.

    Ena.WriteString "*CLS", True

       

End Sub

 

Sub CmdTrigger_Click()

    Ena.WriteString ":TRIG", True ' Making a trigger

End Sub

 

 Sub ReadData()

  Ena.WriteString "*CLS", True ' Clear the status register

  Range("A5:B100").Clear

  Dim i As Integer

  Dim MeasData As Variant

  '*** Get the measurement data.

  Ena.WriteString ":CALC1:DATA:FDAT?", True

  MeasData = Ena.ReadList(ASCIIType_R8, ",")

 

  '*** Display the data on the sheet

  ActiveSheet.Cells(6, 1) = "Data (Primary)"

  ActiveSheet.Cells(6, 2) = "Data (Secondary)"

  For i = 1 To UBound(MeasData)

    ActiveSheet.Cells(i + 6, 1).Value = MeasData(i * 2 - 2)

    ActiveSheet.Cells(i + 6, 2).Value = MeasData(i * 2 - 1)

  Next i

End Sub

 

Sub CmdClose_Click()

    Ena.IO.Close

    Unload Me

End Sub