Chapter 7 NI-488.2 Programming Techniques
© National Instruments Corporation 7-5 NI-488.2 User Manual for Windows
GPIB device to request service, you might choose to pass
ibnotify
a
mask
with RQS (for device-level) or SRQI (for board-level).
The callback function that you register with the
ibnotify
call is invoked
by the NI-488.2 driver when one or more of the mask bits passed to
ibnotify
is TRUE. The function prototype of the callback is as follows:
int __stdcall Callback (
int ud,// unit descriptor
int ibsta,// ibsta value
int iberr,// iberr value
long ibcntl,// ibcntl value
void * RefData// user-defined reference data
)
The callback function is passed a unit descriptor, the current values of the
NI-488.2 global variables, and the user-defined reference data that was
passed to the original
ibnotify
call. The NI-488.2 driver interprets the
return value for the callback as a mask value that is used to automatically
rearm the callback if it is non-zero. For a complete description of
ibnotify
, refer to the NI-488.2 online help. For instructions on accessing
the online help, refer to the Using the NI-488.2 Documentation section in
About This Manual.
Note
The
ibnotify
callback is executed in a separate thread of execution from the rest
of your application. If your application will be performing other NI-488.2 operations while
it is using
ibnotify
, use the per-thread NI-488.2 globals that are provided by the
ThreadIbsta
,
ThreadIberr
,
ThreadIbcnt
, and
ThreadIbcntl
functions described
in the Writing Multithreaded Win32 NI-488.2 Applications section of this chapter. In
addition, if your application needs to share global variables with the callback, use a
synchronization primitive (for example, a semaphore) to protect access to any globals. For
more information about the use of synchronization primitives, refer to the documentation
about using Win32 synchronization objects that came with your development tools.
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 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