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 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.
The sequence interception by an error can not be performed on Excel VBA using VISA.
Option Explicit
Implements VisaComLib.IEventHandler
Dim ioMgr As VisaComLib.ResourceManager
Dim Ena As VisaComLib.FormattedIO488
Dim SRQ As VisaComLib.IEventManager
Private Sub IEventHandler_HandleEvent(ByVal Ena As VisaComLib.IEventManager, ByVal SRQevent As VisaComLib.IEvent, ByVal userHandle As Long)
Call readErr
End Sub
Private Sub UserForm_Initialize()
Set ioMgr = New VisaComLib.ResourceManager
Set Ena = New VisaComLib.FormattedIO488
Set Ena.IO = ioMgr.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"
End With
End Sub
Private Sub CmdCorrect_Click()
With Ena
.WriteString "CALC1:PAR1:DEF S21"
.WriteString "CALC1:PAR1:SEL"
.WriteString "CALC1:FORM MLOG"
End With
End Sub
Private Sub CmdIllegalPara_Click()
With Ena
.WriteString "CALC1:PAR1:DEF S21"
.WriteString "CALC1:PAR1:SEL"
.WriteString "CALC1:FORM LOG" ' "LOG" is incorrect parameter. This line causes an error.
End With
End Sub
Private Sub readErr()
Dim readErr As Variant
Ena.WriteString "SYST:ERR?"
readErr = Ena.ReadList
Ena.WriteString "*CLS", True
MsgBox "Error : " & readErr(0) & " , " & readErr(1), vbOKOnly, "Error occured."
End Sub
Private Sub EndBtn_Click()
Ena.IO.Close
Unload Me
End Sub.