Other topics about Sample Programs
This sample program detects an error via an SRQ.
This program performs the necessary SRQ settings, intentionally sends a command that is incorrect syntax to generate an error. As the standard event status register and service request enable register are enabled, the error generates the SRQ event. When SRQ is detected, the main sequence is interrupted and call the IEventHandler_HandleEvent sub routine. In the subroutine, the error is identified and its error number and message are displayed followed by a message showing that the program is aborted.
See these topics for this programming:
Dim age4982x As VisaComLib.FormattedIO488
Option Explicit
Implements VisaComLib.IEventHandler
Sub IEventHandler_HandleEvent(ByVal vi As VisaComLib.IEventManager, ByVal SRQevent As VisaComLib.IEvent, ByVal userHandle As Long)
'
' This subroutine is called when the SRQ event is occurred.
'
Dim readErr As Variant
age4982x.WriteString "SYST:ERR?" ' Get the error message and number
readErr = age4982x.ReadList
age4982x.WriteString "*CLS" ' Clear the status register
MsgBox "Error : " & readErr(0) & " , " & readErr(1), vbOKOnly, "Error occurred."
End Sub
Sub Err_Detect_Click()
'
' This is a main routine. When SRQ event occurs, the sequence is interrupted and the IEventHandler_HandleEvent is called.
'
Dim gmgr As VisaComLib.ResourceManager
Dim SRQ As VisaComLib.IEventManager
Dim Ans As Integer
Dim strdmy As String
Set gmgr = New VisaComLib.ResourceManager
Set age4982x = New VisaComLib.FormattedIO488
Set age4982x.IO = gmgr.Open("GPIB0::17::INSTR") ' Sets the GPIB address and select code.
age4982x.IO.Timeout = 5000 ' Sets the time out time
Set SRQ = age4982x.IO
With age4982x
.WriteString "*RST" '
.WriteString "*ESE 60" ' Sets bits 2, 3, 4 and 5 of the standard event status register to be enabled
.WriteString "*SRE 32" ' Sets bit 5 of the service request enable register to 1.
.WriteString "*CLS"
.WriteString "*OPC?"
strdmy = .ReadString
End With
SRQ.InstallHandler EVENT_SERVICE_REQ, Me ' Enable SRQ event
SRQ.EnableEvent EVENT_SERVICE_REQ, EVENT_HNDLR '
Do
Ans = Val(InputBox("Select" & vbCrLf & "1: No Error Sequence" & vbCrLf & "2: Error Sequence" & vbCrLf & "3: End of program", , 1))
Select Case Ans
Case 1 ' Correct Sequence
With age4982x
.WriteString ":SOUR:LIST:STAT ON"
.WriteString ":DISP:LIST:TYPE PLOT"
End With
Case 2 ' Sequence with Error
With age4982x
.WriteString ":SOUR:LIST:STAT ON"
.WriteString ":DISP:LIST:TYPE PLO" ' Generate an illegal parameter error by incorrect parameter
End With
End Select
Loop While Ans <> 3
SRQ.DisableEvent ALL_ENABLED_EVENTS, EVENT_ALL_MECH, 0 ' Disable SRQ event
End Sub