How do I get error information about failed NI-488 calls?

NI-488.2

How do I get error information about failed NI-488.2 calls?

Each NI-488.2 call updates three global functions to reflect the status of the device or board that you are using. These global status functions are the status word (Ibsta), the error function (Iberr), and the count function (Ibcnt). They contain useful information about the last NI-488.2 call that was executed for any given process. Your application should check these functions after each NI-488.2 call. For more information about each status function, refer to the following sections.

If you are writing a multithreaded application, use the thread-specific copies of the status functions in your application. To access the thread-specific copies, use the ThreadIbsta, ThreadIberr, and ThreadIbcnt calls.

Status Word (Ibsta)

Ibsta is the GPIB status word. It contains information about the state of the GPIB and your GPIB hardware. The value stored in Ibsta is the return value of all of the traditional NI-488.2 calls, except ibfind and ibdev. You can examine various status bits in Ibsta and use that information to determine what to do next in your application. For more information about the status bits in Ibsta, refer to the Ibsta Status Bit Values table.

To check for errors after each NI-488.2 call, use the ERR bit in Ibsta, as follows:

if (Ibsta() & ERR)

printf("GPIB error encountered");

Error Function (Iberr)

Iberr is the GPIB error variable. If a call failed with an error, the ERR bit is set in Ibsta. The Iberr value describes the GPIB error that occurred. For more information about the Iberr values, refer to the Error Codes and Solutions table.

Count Function (Ibcnt)

Ibcnt is the count function. It contains information about the number of bytes that went across the GPIB in the most recent I/O operation.

The count function is updated after all I/O operations like ibrd, ibwrt, SendList, and SendCmds. If you are reading data, the count function indicates the number of bytes read. If you are sending data or commands, the count variables reflect the number of data or command bytes sent.

If the data that you are reading contains ASCII characters, you can use Ibcnt to NULL terminate the string and treat it like any other ASCII string. For example, you can use printf to print the result to the screen:

char rdbuf[21];

ibrd (ud, rdbuf, 20);

if (!(Ibsta() & ERR)){

rdbuf[Ibcnt()] = '\0';

printf ("Read in string: %s\n", rdbuf);

}

else {

// GPIB Error encountered!

}

In addition, Ibcnt may return information from non-I/O functions, such as EDVR error codes.


Return to Frequently Asked Questions