beautypg.com

Sample program – Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual

Page 78

background image

II. SOFTWARE GUIDES - 8. Driver488/DRV

8E. Microsoft C

Personal488 User’s Manual, Rev. 3.0

II-63

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
void main (void){
int ieee
char response[256];
float voltage;
int i;
float sum;
char hundred[1700];
ieee=open(“ieee”,O_RDWR | O_BINARY);
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);
}
ieeewt(“hello\n”);
ieeerd(response);
printf(“%s\n”,response);
ieeewt(“status\n”);
ieeerd(response);
printf(“%s\n”,response);
ieeewt(“output 16;F0R0X\n”);
ieeewt(“enter 16\n”);
ieeescnf(“%*4s%e”,&voltage);
printf(“The read value is %g\n”,voltage);
sum=0.0;
for (i=0; i<10; i++) {
ieeewt(“enter 16\n”);
ieeescnf(“%*4s%e”,&voltage);
sum=sum+voltage;
}
printf(“The average of 10 readings is %g\n”,sum/10.0);
ieeeprtf(“ENTER 16 #1700 BUFFER %d:%d\n”,
segment(hundred),offset(hundred));
for (i=0; i<1700; i++) putchar(hundred[i]);
ieeeprtf(“ENTER 16 #1700 BUFFER continue\n”,
segment(hundred),offset(hundred));
ieeewt(“status\n”);
ieeerd(response);
printf(“%s\n”,response);
int cklpint();
ieee_cki = cklpint;
ieee_isr = isr;
ieeewt(“arm srq\n”);