beautypg.com

Gw-basic (for gw-basic or interpreted basic) – Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual

Page 121

background image

8L. Language-Specific Information

II. SOFTWARE GUIDES - 8. Driver488/DRV

II-106

Personal488 User’s Manual, Rev. 3.0

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.

GW-BASIC (for GW-BASIC or Interpreted BASIC)

Use of Direct DOS I/O Devices

Once Driver488/DRV has been installed in your system, it is ready to begin controlling IEEE 488 bus
devices. To show how this is done, we develop a short program in BASIC to control a Keithley
Instruments Model 195 digital multimeter. The complete sample program is provided on the
Driver488/DRV disk as

195DEMO.BAS

in the

\MSBASIC

directory.

BASIC VARPTR & SADDR

The

BASIC VARPTR

and

SADDR

functions must be used with caution. The first time a variable such as

I

or

ST$

is encountered, or an array such as

R%()

is dimensioned, space is made for it in BASIC’s data

space. The other variable or arrays may be moved to make room for the new item. If the memory
location of an item must be fixed, then BASIC cannot be allowed to encounter any new variables or
arrays. For example, in the

ENTER

statement shown above, Driver488/DRV is told the memory address

of

R$

(for GW-BASIC,

R%(0)

). Then, while the transfer is going on, the Driver488/DRV status is read

into the string variable

ST$

. If

ST$

has not been used previously then BASIC would have to create a

new

ST$

and might move

R$

. Of course, Driver488/DRV would have no way of knowing that

R$

has

been moved, and the data would not be placed correctly into

R$

.