Criterr.asm (microsoft c & turbo c), Sample program – Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual
Page 96
II. SOFTWARE GUIDES - 8. Driver488/DRV
8H. Turbo C
Personal488 User’s Manual, Rev. 3.0
II-81
CRITERR.ASM (Microsoft C & Turbo C)
Normally, when Driver488/DRV detects an error, perhaps due to a syntax error in a command, or due
to an IEEE 488 bus error (such as time out on data transfer), it responds with an I/O error to DOS.
When this happens, DOS normally issues an
ABORT
,
RETRY
or
IGNORE
message and waits for a
response from the keyboard. There is no way for the user’s program to detect such an error, determine
the cause, and take appropriate action. However, DOS does provide a method of redefining the action
to be taken on such a “critical error”.
CRITERR.ASM
contains a critical error handler that, when
invoked, makes it appear to the calling program that some less-critical error has occurred. The critical
error handler is installed by
CRIT_ON()
and removed by
CRIT_OFF()
.The critical error handler is
also automatically removed by DOS when the program exits.
The following program fragment demonstrates the use of the critical error handler:
#include “criterr.h”
crit_on(ieee);
if (ieeewt(“output 16;F0X”) == -1) {
printf(“Error writing F0X to device 16, \n”);
crit_off();
ioctl_wt(ieee,"break",5);
ieeewt(“eol out lf\r\n”);
ieeewt(“status\n”);
ieeerd(response);
printf(“status = %s\n”,response);
crit_on(ieee);
}
We must first
#include
the header file with the definitions of the critical error routines. We then
enable critical error trapping with
CRIT_ON
which takes as a parameter the handle of the file for which
critical error trapping is to be enabled. Only read and write commands to that handle are trapped.
Errors caused by other actions, or associated with other files are not trapped. Error trapping may only
be enabled for one file at a time.
Now, if
IEEEWT
signals an error by returning a
-1
, we can check what happened. We first
PRINTF
an
error message, then we turn critical error trapping off with
CRIT_OFF
so that, if another critical error
occurs, we get the
ABORT
,
RETRY
or
IGNORE
message and know a catastrophic double error has
occurred. We then
IOCTL_WT(_BREAK_)
to force Driver488/DRV to listen to our next command.
The
IOCTL_WT
also resets the
EOL OUT
terminator so we can be sure that Driver488/DRV detects the
end of our commands. We next reset the
EOL OUT
terminator to our preferred line feed only and ask
Driver488/DRV for its status. On receiving the response, we could interpret the status and take
whatever action is appropriate. However, in this example, we just display the status. Finally, we re-
enable the critical error handler and continue with the program.
Sample Program
#include “ieeeio.h”
#include .h
void main (void) {
char response[256];
float voltage;
int i;
float sum;
char hundred[1700];
ieee=open(“ieee”,O_RDWR | O_BINARY);
ieee=open(“ieee”,O_rdwr);
rawmode(ieee);
ioctl_wt(ieee,"break",5);
ieeewt(“reset\r\n”);
ieeewt(“eol out lf\r\n”);
ieeewt(“eol in $0\n”);
ieeewt(“fill error\n”);
if (ieeeinit() == -1) {
printf(“Cannot initialize IEEE system.\n”);
exit(1);