How to Programmatically Check the Status of Your GPIB Board
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:
NI-488.2 User Manual (dynamic search for current versions)
Reader Comments | Submit a comment »
Should the ERR check in the example be EERR
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.
- paul.wallace@bookham.com - Oct 14, 2004
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
