Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual
Page 89

8H. Turbo C
II. SOFTWARE GUIDES - 8. Driver488/DRV
II-74
Personal488 User’s Manual, Rev. 3.0
Driver488/DRV can accept commands only when it is in a quiescent, ready state. While
Driver488/DRV should normally be ready, it is possible that it was left in some unknown state by a
previous program failure or error. In order to force Driver488/DRV into its quiescent state, we use the
IOCTL_WT
function:
ioctl_wt(ieee,"break",5);
This
IOCTL_WT
function is equivalent to the BASIC statement
IOCTL#1,“BREAK”
which sends the
BREAK
command through a “back door” to Driver488/DRV. Driver488/DRV recognizes this “back
door” command regardless of what else it might be doing and resets itself so that it is ready to accept a
normal command. We can then completely reset the Driver488/DRV with the
RESET
command:
ieeewt(“reset\r\n”);
which resets the operating parameters of the Driver488/DRV back to their normal values (those that
were set during system boot by the
DRVR488
DOS command). Notice that the
EOL OUT
terminators
that mark the end of a Driver488/DRV command are reset to carriage return and line feed by the
IOCTL_WT
command. Thus, the
RESET
command must be terminated by both a carriage return (
\r
)
and a line feed (
\n
). As it is more convenient if Driver488/DRV accepts line feed only as the
command terminator, we use the
EOL OUT
command to set the command terminator to line feed (
\n
):
ieeewt(“eol out lf\r\n”);
Notice that this command must also be terminated by both a carriage return and a line feed because the
command terminator is not changed until after the
EOL OUT
command is executed.
Character strings in C are normally terminated by a null (an
ASCII 0
). Thus, it is appropriate for
Driver488/DRV to terminate its responses to the program with a null so that the response can be treated
as a normal character string. We can use the
EOL IN
command to configure Driver488/DRV so that it
does provide an ASCII null terminator:
ieeewt(“eol in $0\n”);
Finally, we enable
SEQUENCE - NO DATA AVAILABLE
error detection by setting the
FILL
mode to
ERROR
:
ieeewt(“fill error\n”);
All the commands discussed so far:
OPEN
,
RAWMODE
,
IOCTL_WT
,
RESET
,
EOL OUT
,
EOL IN
and
FILL
ERROR
are part of the
IEEEINIT
function included in
IEEEIO.C
.
IEEEINIT
returns a zero if these
steps were executed successfully, and a
-1
if some error was encountered. Thus, to accomplish all the
above steps, we just use the following:
#include “ieeeio.h”
#include .h
if (ieeeinit() == -1) {
printf(“Cannot initialize IEEE system.\n”);
exit(1);
}
The two
INCLUDE
statements provide the program with definitions of the standard I/O and IEEE I/O
functions so they can be referenced by the demo program.
IEEEINIT
is called to initialize the system,
and if it indicates an error (returns a
-1
), we print an error message and exit. If there was no error, we
just continue with the program.
Once everything is reset, we can test the communications and read the Driver488/DRV revision number
with the
HELLO
command:
char response[256];
ieeewt(“hello\n”);
ieeerd(response);
printf(“%s\n”,response);
We first
IEEEWT
the
HELLO
command, then
IEEERD
the response from Driver488/DRV into the
character string response (
IEEEWT
and
IEEERD
are both supplied in
IEEEIO.C
). Finally, we display
the response with a
PRINTF
.