Other topics about Sample Programs
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, the program exits after printing a measurement completion message.
See Waiting for the End of Measurement for this programming.
Option Explicit
Implements VisaComLib.IEventHandler
'*** The variables of the resource manager
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()
'*** Variable declaration.
Dim i As Double, dummy As Integer
Range("A5:B500").Clear
'*** Instrument I/O declarlation
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") ' You can change VISA address
Ena.IO.timeout = 100000 ' TimeOut time should be greater than the measurement time.
'*** SRQ declarlation
Set SRQ = Ena.IO
SRQ.InstallHandler EVENT_SERVICE_REQ, Me
SRQ.EnableEvent EVENT_SERVICE_REQ, EVENT_HNDLR
'* Clears the operation status event register and the status byte register.
Ena.WriteString "*CLS", True
'* Aborts the trigger and sets the trigger source to the bus trigger.
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
End Sub
Sub CmdTrigger_Click()
'* Making a trigger
Ena.WriteString ":TRIG", True
End Sub
Sub ReadData()
'* Clear the status register
Ena.WriteString "*CLS", True
Range("A5:B500").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()
'* Close
Ena.IO.Close
Unload Me
End Sub