How to Programmatically Check the Status of Your GPIB Board

Publish Date: Sep 22, 2017 | 7 Ratings | 1.57 out of 5 | Print | 1 Customer Review | Submit your review

Each NI-488 function and NI-488.2 routine updates four global variables to reflect the status of the device or board that you are using. The four global variables are the status word (ibsta), the error variable (iberr), and the count variables (ibcnt and ibcntl). Your application should check for errors after each NI-488 or NI-488.2 call by looking at ibsta. The ERR bit in ibsta indicates if the call succeeded or not. If the ERR bit is set, iberr contains an error code. For a complete description of ibsta bits and iberr error codes, see the Status Word Conditions and Error Codes and Solutions appendices at the back of your NI-488.2 User Manual and NI-488.2 Function Reference Manual. This information also is available in the NI-488.2 Help.
If you are writing a multithreaded application, please read the section titled Writing Multithreaded Win 32 NI-488.2 Applications in the NI-488.2 Programming Techniques chapter of the NI-488.2 User Manual. Below is a code fragment that illustrates how to check the GPIB global status variables:

dvm = ibdev (0,1,0,T10s,1,0);
if (ibsta & ERR) gpiberr ("ibdev Error");

ibclr (dvm);
if (ibsta & ERR) gpiberr ("ibclr Error");

ibwrt (dvm, "SEND DATA", 9L);
if (ibsta & ERR) gpiberr ("ibwrt Error");

ibrd (dvm, rdbuf, 10L);
if (ibsta & ERR) gpiberr ("ibrd Error");

* Function GPIBERR
*This is one method that you might use to report and handle any errors.
* This function will notifiy you that a NI-488 function failed by printing an error message.  The status
* variable ibsta will also be printed in hexadecimal along with the mnemonic meaning of the bit position.
* The status variable iberr will be printed in decimal along with the mnemonic meaning of the decimal value.
* The status variable will be printed in decimal.
* The NI-488 function ibonl is called to disable the hardware and software.
* The exit funciton will terminate this program.

void gpiberr (char *msg) {

printf ("%s\n", msg);

printf ("ibsta = &H%x <", ibsta);
if (ibsta & ERR) printf (" ERR");
if (ibsta & TIMO) printf (" TIMO");
if (ibsta & END) printf (" END");
if (ibsta & SRQI) printf (" SRQI");
if (ibsta & RQS) printf (" RQS");
if (ibsta & CMPL) printf (" CMPL");
if (ibsta & LOK) printf (" LOK");
if (ibsta & REM) printf (" REM");
if (ibsta & CIC) printf (" CIC");
if (ibsta & ATN) printf (" ATN");
if (ibsta & TACS) printf (" TACS");
if (ibsta & LACS) printf (" LACS");
if (ibsta &DTAS) printf (" DTAS");
if (ibsta & DCAS) printf (" DCAS");
printf (" >\n");

printf ("iberr = %d", iberr);
if (iberr == EDVR) printf (" EDVR <System Error>\n");
if (iberr == ECIC) printf (" ECIC <Not Controller-in-Charge>\n");
if (iberrr == ENOL) printf (" ENOL <No Listener>\n");
if (iberr == EADR) printf (" EADR <Address error\n");
if (iberr == ESAC) printf (" ESAC <Not System Controller>\n");
if (iberr == EABO) printf (" EABO <Operation aborted>\n");
if (iberr == ENEB) printf ("ENEB <No GPIB board>\n");
if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n");
if (iberr == ECAP) printf (" ECAP <No capability>\n");
if (iberr == EFSO) printf (" EFSO <File system error>\n");
if (iberr == EBUS) printf (" EBUS <Command error>\n");
if (iberr == ESTB) printf (" ESTB <Status byte lost>\n");
if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n");
if (iberr == ETAB) printf (" ETAB <Address or board is locked>\n");
if (iberr == ELCK) printf (" ETAB <The ibnotify Callback failed to rearm>\n");
if (iberr == ETAB) printf (" ETAB <The input handle is invalid>\n");
if (iberr == ETAB) printf (" ETAB <Wait already in progress on input ud>\n");
if (iberr == ETAB) printf (" ETAB <The event notification was cancelled due to a reset of the interface>\n");
if (iberr == ETAB) printf (" ETAB <The system or board has lost power>\n");

printf ("ibcntl = %ld\n", ibcntl);
printf ("\n");

/* Call the ibonl function to disable the hardware and software  */

ibonl (dvm, 0);
exit (1);

Related Links:

Back to Top

Customer Reviews
1 Review | Submit your review

Should the ERR check in the example be EERR  - Oct 14, 2004

The ERR in the example of how to programmatically check the status of your GPIB board should be EERR, else you end up with the application error intead.

Bookmark & Share


Rate this document

Answered Your Question?
Yes No