National Instruments NI-488.2 Benutzerhandbuch

Seite von 135
Chapter 3
Developing Your NI-488.2 Application
3-8
www.natinst.com
Programming Models
Applications That Communicate with a Single GPIB Device
This section describes items you should include in your application and 
provides general program steps with an NI-488.2 example. 
Items to Include
Include the following items in your application:
Header files—In a C application, include the header files 
windows.h
 
and 
decl-32.h
. The standard Windows header file, 
windows.h
contains definitions used by 
decl-32.h
, and 
decl-32.h
 contains 
prototypes for the NI-488.2 calls and constants that you can use in your 
application. 
Error checking—Check for errors after each NI-488.2 call. 
Error handling—Declare and define a function to handle NI-488.2 
errors. This function takes the device offline and closes the application. 
If the function is declared as:
void gpiberr (char * msg); /*function prototype*/
Then, your application invokes it as follows:
if (ibsta & ERR) {
gpiberr("NI-488.2 error");
}
General Program Steps and Examples
The following steps show you how to use the device-level traditional 
NI-488.2 calls in your application. The NI-488.2 software includes the 
source code for an example written in C, 
devquery.c
, and the source code 
for the example written to use direct entry to access 
gpib-32.dll
dlldevquery.c
. The NI-488.2 software also includes a sample program 
written in Visual Basic, 
devquery.frm
Initialization
Step 1. Open a Device
Use 
ibdev
 to open a device handle. The 
ibdev
 function requires the 
following parameters:
Connect board index (typically 0, for 
GPIB0
).
Primary address for the GPIB instrument (refer to the instrument user 
manual or use the 
FindLstn
 function to dynamically determine the