Preventing Hang-Ups
The “Main” section of the program (lines 10-220) act as a shell that prevents your basic program from ever
hanging up due to I/O that is not proceeding. It identifies the LINE NUMBER of lines that have RUN TIME
ERRORS or that have TIMED OUT.
Lines 70 and 80, combined with placing all application code in a lower level context (Main), is what causes
a TIMEOUT to be reported as an ERROR. BASIC ERRORS contain the line number whereas, TIMEOUTs
do not. The BASIC ERRORS method provides the advantage of providing the line number of a TIMEOUT.
The “ON TIMEOUT 8,3 GOTO End” interrupt branching can only occur if you are in the same context
when the TIMEOUT occurs. Since all application code is in a lower level context (Main), this branch cannot
be taken. Since this is a fatal condition, BASIC reports the timeout as a ERROR.
Context levels in BASIC/IBASIC provide a level of interrupt flow control. In BASIC/IBASIC the interrupt
destinations specified by GOSUB or GOTO are only taken when you are in the defining context. CALL or
RECOVER destinations are branched to when in the current or lower level context. All lower level contexts
inherit the interrupt specifications of the current context, however, lower contexts may freely redefine this.
This allows application code starting in SUB Main to override the ON TIMEOUT and ON ERROR that are
established in lines 70 and 80. However, if this is not done a very good default error handler is already in
effect because of the inheritance.
Using the “E13xx_errors” Subprogram
When the shell detects an ERROR, it will call the subprogram “E13xx_errors”. This queries instruments for
errors. Querying instruments for errors is one of the most important steps in debugging I/O code. Often
timeouts are caused by doing an ENTER after having sent incorrect commands to instruments.
If the subprogram “E13xx_errors” detects any errors in an instrument, it also calls a routine that queries
instruments for all of its command parameter values. You can use this information to help locate the bug.
To expand this shell to include more instruments, add the following:
1. ASSIGN a name and address to the new instrument i.e. lines 40, 50.
2. Place the new instrument name into the labeled common “ COM /Instr”.
3. Add an error reading loop for each instrument in the system (lines 300-380) into the subprogram
“E13xx_errors”.
4. Add a subprogram such as “E1300_stat” or “E1326_stat” that reads all of the command
parameter values for the new instrument. Writing this program is an excellent way to become
familiar with a new instrument.
Using “PAUSE”, “Step”, and “CONT”
Since the Shell prevents I/O hang ups, BASIC/IBASIC’s PAUSE, STEP, and CONT may now be used
effectively to debug programs. When a program doesn’t seem to be proceeding correctly, use PAUSE then
STEP to trace the flow. Type variable names to see their value when PAUSEd, and finally use CONT to
proceed at full speed.
C-10 Debugging VXI SCPI Programs