Application Examples Chapter 2
NI-488.2 User Manual for Windows 2-6 © National Instruments Corp.
Example 3: Asynchronous I/OThis example illustrates how an application conducts data transfers with a GPIB device
and immediately returns to perform other non-GPIB related tasks while GPIB I/O is
occurring in the background. This asynchronous mode of operation is particularly useful
when the requested GPIB activity may take some time to complete.
In this example, a research biologist is trying to obtain CAT scans of a laboratory
animal's liver. She will print out a color copy of each scan as it is acquired. The entire
operation is computer-controlled. The CAT scan machine sends the images it acquires to
a computer that has the NI-488.2 software installed and is connected to a GPIB color
printer . The biologist is familiar with the command set of her color printer, as described
in the color printer's user manual. She acquires and prints images with the aid of an
application program she wrote using high-level GPIB commands. The following steps
correspond to the program flowchart in Figure 2-3.
1. The application initializes the GPIB by bringing the interface board in the computer
online.
2. An image is scanned in.
3. The application sends the GPIB printer a command to print the new image and
immediately returns without waiting for the I/O operation to be completed.
4. The application saves the image obtained to a file.
5. The application inquires as to whether the printing operation has completed by
issuing a GPIB wait command. If the status reported by the wait command indicates
completion (CMPL is in the status returned) and more scans need to be acquired,
Steps 2 through 5 are repeated until the scans have all been acquired. If the status
reported by the wait command in Step 5 does not indicate that printing is finished,
statistical computations are performed on the scan obtained and Step 5 is repeated.
6. As a cleanup step before exiting, the application returns the interface board to its
original state by taking it offline.