Chapter 3
Developing Your Application
© National Instruments Corp.
3-5
NI-488.2M UM for Windows NT
The language header file included on your distribution disk contains the mnemonic
constants for
ibsta
. You can check a bit position in
ibsta
by using its numeric value
or its mnemonic constant. For example, bit position 15 (hex 8000) detects a GPIB error.
The mnemonic for this bit is ERR. To check for a GPIB error, use either of the following
statements after each NI -488 function and NI-488.2 routine as s hown:
if (ibsta & ERR) gpiberr();
or
if (ibsta & 0x8000) gpiberr();
where
gpiberr()
is an error-handling routine.
Error Variable – iberr
If the ERR bit is set in the status word (
ibsta
), a GPIB error has occurred. When an
error occurs, the error type is specified by the value in
iberr
.
Note:
The value in
iberr
is meaningful as an error type only when the ERR bit is
set in
ibsta
, indicating that an error has occurred.
For more information on error codes and solutions refer to Chapter 4, Debugging Your
Application , or Appendix B, Error Codes and Solutions.
Count Variables – ibcnt and ibcntl
The count variables are updated after each read, write, or command function.
ibcnt
and
ibcntl
are 32-bit integers. On some systems, like MS-DOS,
ibcnt
is a 16-bit
integer, and
ibcntl
is a 32-bit integer. For cross-platform compatibility, all
applications should use
ibcntl
. If you are reading data, the count variables indicate the
number of bytes read. If you are sending data or commands, the count variables reflect
the number of bytes sent.
In your application program, you can use the count variables to null-terminate an ASCII
string of data received from an instrument. For example, if data is received in an array of
characters, you can use
ibcntl
to null-terminate the array and print the measurement on
the screen as follows:
char rdbuf[512];
ibrd (ud, rdbuf, 20L);
if (!(ibsta & ERR)){
rdbuf[ibcntl] = '\0';
printf ("Read: %s\n", rdbuf);
}
else {
error();
}