National Instruments NI-488.2 User Manual

Page 80

Advertising
background image

Chapter 8

NI-488.2 Programming Techniques

NI-488.2 User Manual

8-8

ni.com

// If the ERR bit is set in LocalIbsta, then print an error

// message and return.

if (LocalIbsta & ERR) {

printf ("GPIB error %d has occurred. No more callbacks.\n",

LocalIberr);

DeviceError = TRUE;

return 0;

}

// Read the serial poll byte from the device. If the ERR bit is set

// in ibsta, then print an error message and return.

LocalIbsta = ibrsp (LocalUd, &SpollByte);

if (LocalIbsta & ERR) {

printf ("ibrsp failed. No more callbacks.\n");

DeviceError = TRUE;

return 0;

}

// If the returned status byte equals the expected response, then

// the device has valid data to send; otherwise it has a fault

// condition to report.

if (SpollByte != expectedResponse) {

printf("Device returned invalid response. Status byte = 0x%x\n",

SpollByte);

DeviceError = TRUE;

return 0;

}

// Read the data from the device. If the ERR bit is set in ibsta,

// then print an error message and return.

LocalIbsta = ibrd (LocalUd, ReadBuffer, 40L);

if (LocalIbsta & ERR) {

printf ("ibrd failed. No more callbacks.\n");

DeviceError = TRUE;

return 0;

}

// The string returned by ibrd is a binary string whose length is

// specified by the byte count in ibcntl. However, many GPIB

// instruments return ASCII data strings and this example makes this

// assumption. Because of this, it is possible to add a NULL

// character to the end of the data received and use the printf()

// function to display the ASCII data. The following code

// illustrates that.

ReadBuffer[ibcntl] = ‘\0’;

Advertising