Chapter 7 NI-488.2 Programming Techniques
NI-488.2 User Manual for Windows 7-10 www.natinst.com
modified by the call. For more information about the use of synchronization
primitives, refer to the documentation about using Win32 synchronization
objects that came with your development tools.
If you choose not to use process-global variables, you can access per-thread
copies of the NI-488.2 global variables using a special set of NI-488.2 calls.
Whenever a thread makes a NI-488.2 call, the driver keeps a private copy
of the NI-488.2 globals for that thread. The driver keeps a separate private
copy for each thread. The following code shows the set of functions you can
use to access these per-thread NI-488.2 global variables:
int ThreadIbsta(); // return thread-specific ibsta
int ThreadIberr(); // return thread-specific iberr
int ThreadIbcnt(); // return thread-specific ibcnt
long ThreadIbcntl(); // return thread-specific ibcntl
In your application, instead of accessing the per-process NI-488.2 globals,
substitute a call to get the corresponding per-thread NI-488.2 global. For
example, the following line of code,
if (ibsta & ERR)
could be replaced by,
if (ThreadIbsta() & ERR)
A quick way to convert your application to use per-thread NI-488.2 globals
is to add the following
#define
lines at the top of your C file:
#define ibsta ThreadIbsta()
#define iberr ThreadIberr()
#define ibcnt ThreadIbcnt()
#define ibcntl ThreadIbcntl()
Note
If you are using
ibnotify
in your application (see the Asynchronous Event
Notification in Win32 NI-488.2 Applications section of this chapter), the
ibnotify
callback is executed in a separate thread that is created by the NI-488.2 driver. Therefore,
if your application makes NI-488.2 calls from the
ibnotify
callback function and makes
NI-488.2 calls from other places, you must use the
ThreadIbsta
,
ThreadIberr
,
ThreadIbcnt
, and
ThreadIbcntl
functions described in this section, instead of the
per-process NI-488.2 globals.