Other topics about Sample Programs
This sample program demonstrates how to use an SRQ to detect the occurrence of an error.
This program sets SRQs and then intentionally sends an invalid parameter (CALC1:FORM LOG) to generate an error to be handled by this program. In the error handling part, this program examines the error, displays the error number and error message, and then displays the message indicating the suspension of the program. See Detecting Occurrence of an Error for this programming.
Dim Ena As VisaComLib.FormattedIO488
Option Explicit
Implements VisaComLib.IEventHandler
Private Sub IEventHandler_HandleEvent(ByVal vi As VisaComLib.IEventManager, ByVal SRQevent As VisaComLib.IEvent, ByVal userHandle As Long)
On Error Resume Next
Dim readErr As Variant
Dim i As Integer
Ena.WriteString "SYST:ERR?"
readErr = Ena.ReadList
MsgBox "Error : " & readErr(0) & " , " & readErr(1), vbOKOnly, "Error occured."
End
End Sub
Private Sub Err_Detect_Click()
Dim gmgr As VisaComLib.ResourceManager
Dim SRQ As VisaComLib.IEventManager
Dim strdmy As String
On Error GoTo CommandButton1_Error
Set gmgr = New VisaComLib.ResourceManager
Set Ena = New VisaComLib.FormattedIO488
Set Ena.IO = gmgr.Open("GPIB0::17::INSTR")
Set SRQ = Ena.IO
SRQ.InstallHandler EVENT_SERVICE_REQ, Me, 1, 0
SRQ.EnableEvent EVENT_SERVICE_REQ, EVENT_HNDLR
With Ena
.WriteString "*RST"
.WriteString "*ESE 60"
.WriteString "*SRE 32"
.WriteString "*CLS"
.WriteString "*OPC?"
strdmy = .ReadString
End With
With Ena
.WriteString "CALC1:PAR:COUN 2"
.WriteString "CALC1:PAR1:DEF S21"
.WriteString "CALC1:PAR1:SEL"
.WriteString "CALC1:FORM MLOG"
.WriteString "CALC1:PAR2:DEF S11"
.WriteString "CALC1:PAR2:SEL"
.WriteString "CALC1:FORM LOG" ' This parameter causes error
.WriteString "*OPC?"
strdmy = .ReadString
End With
SRQ.DisableEvent ALL_ENABLED_EVENTS, EVENT_ALL_MECH, 0
Exit Sub
CommandButton1_Error:
MsgBox "Error Occured. Error=" & vbTab & Err.Number & " , " & Err.Description
End Sub