User`s guide
80 Agilent VISA User’s Guide
3 Programming with VISA
Trapping Errors
This section provides guidelines for trapping errors,
including:
• Trapping Errors
• Exception Events
Trapping Errors
The sample programs in this guide show specific VISA
functionality and do not include error trapping. Error
trapping, however, is good programming practice and is
recommended in all your VISA application programs. To trap
VISA errors you must check for VI_SUCCESS after each
VISA function call.
If you want to ignore WARNINGS, you can test to see if err
is less than (<) VI_SUCCESS. Since WARNINGS are greater
than VI_SUCCESS and ERRORS are less than VI_SUCCESS,
err_handler would only be called when the function returns
an ERROR. For example:
if(err < VI_SUCCESS) err_handler (vi, err);
Sample: Checking for VI_SUCCESS
This sample illustrates checking for VI_SUCCESS. If
VI_SUCCESS is not returned, an error handler (written by
the programmer) is called. This must be done with each
VISA function call.
ViStatus err;
.
.
err=viPrintf(vi, "*RST\n");
if (err < VI_SUCCESS) err_handler(vi, err);
.
.