Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 6, 2006


Feedback


Yes No

Related Categories

Development Topic

Related Links - Developer Zone

Related Links - Products and Services

How to Programmatically Check the Status of Your GPIB Board

7 ratings | 1.57 out of 5
Print
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:
NI-488.2 User Manual (dynamic search for current versions)

7 ratings | 1.57 out of 5
Print

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/).