Specifications

206 Chapter 11
Error Handling
Example Program for Error Handling
Using the macro (E4991A VBA)
Example 11-2 shows a program that uses an event to detect an error from the E4991A. This
program performs error handling when the E4991A shows a measurement failure. It
generates an error message and stops execution of the macro.
This program is saved as error.bas (lines 10 - 300) and bsc_meas.cls (lines 1000 - 4050) on
the sample programs disk.
Lines 40 - 50 Defines the variable Err to use for the event created in the class
module (class name: clsErr). Next, sets the object variable (Err.Evnt)
to the E4991A library.
Line 130 Clears the Status Byte Register, the Standard Event Status Register,
and the error queue.
Lines 140 - 160 Turns on Trace 1 and activates the sweep averaging function.
Lines 180 - 200 Sets the trigger source for the internal trigger and turns off the
continuous activation of the trigger system. Then, resets the trigger
system and sets the trigger sequence to the idle state.
Lines 220 - 230 Reads the on/off status of the sweep averaging function and substitutes
a variable for the status. Next, when the sweep averaging function is
set on, resets the averaging and returns the averaging counter to zero.
Lines 250 - 260 Starts the sweep and substitutes a variable for sweep completion.
Displays a message of “Sweep Aborted” when sweep is aborted during
the measurement.
Line 280 Disassociates the object variable used for the event function.
Line 1000 Defines the variable (Evnt) as the Public type so that the event
procedure can be used in different procedures.
Lines 2000 - 2050 Terminates the program when a “PLL unlock” error occurs inside the
E4991A.
Lines 3000 - 3050 Terminates the program when a “DC bias overload” error occurs
inside the E4991A.
Lines 4000 - 4050 Forces the program to end when the “RF overload” error occurs inside
the E4991A.
Example 11-2 Error Detection Using Event
10 Sub Main()
20 Dim trc As Integer
30 Dim swp_count As Integer, swp_bool As Integer, bool As
Integer
40
50 Dim Err As New clsErr
60 Set Err.Evnt = New E4991ALib.Application
70
80 trc = 1
90 swp_count = 16
100
110 ' E4991A settings
120
130 SCPI.Output "*CLS"
140 SCPI.Output "DISP:TRAC" & CStr(trc) & " ON"