Chapter 8 NI-488.2 Programming Techniques
NI-488.2 User Manual 8-6 ni.com
ibnotify Programming ExampleThe following code is an example of how you can use ibnotify in your
application. Assume that your GPIB device is a multimeter that you
program it to acquire a reading by sending "SEND DATA". The multimeter
requests service when it has a reading ready, and each reading is a floating
point value.
In this example, globals are shared by the Callback thread and the main
thread, and the access of the globals is not protected by synchronization.
In this case, synchronization of access to these globals is not necessary
because of the way they are used in the application: only a single thread is
writing the global values and that thread only adds information (increases
the count or adds another reading to the array of floats).
Note The following example is written using the GpibNotifyCallback_t definition
for Windows. Refer to the gpib header file, ni488.h, for the proper definition of the
Callback thread for your platform. Other than a possible minor change in the definition
of the Callback thread, this example will work on all platforms.
#include <stdio.h>
#include "ni488.h"
int __stdcall MyCallback (int LocalUd, int LocalIbsta, int LocalIberr,
long LocalIbcntl, void *RefData);
int ReadingsTaken = 0;
float Readings[1000];
BOOL DeviceError = FALSE;
char expectedResponse = 0x43;
int main()
{
int ud;
// Assign a unique identifier to the device and store it in the
// variable ud. ibdev opens an available device and assigns it to
// access GPIB0 with a primary address of 1, a secondary address of 0,
// a timeout of 10 seconds, the END message enabled, and the EOS mode
// disabled. If ud is less than zero, then print an error message
// that the call failed and exit the program.
ud = ibdev (0,// connect board
1, // primary address of GPIB device
0, // secondary address of GPIB device
T10s, // 10 second I/O timeout
1, // EOT mode turned on