Ibnotify programming example, Ibnotify programming example -6 – National Instruments NI-488.2 User Manual

Page 81

Advertising
background image

Chapter 8

NI-488.2 Programming Techniques

NI-488.2 User Manual

8-6

ni.com

ibnotify Programming Example

The 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 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,

ni4882.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 "ni4882.h"

int __stdcall MyCallback (int LocalUd, unsigned long LocalIbsta, unsigned

long LocalIberr,

unsigned long LocalIbcnt, 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

Advertising