Application Examples
Chapter 2
NI-488.2M UM for Windows NT
2-8
© National Instruments Corp.
Example 4: End-of-String Mode
This example illustrates how to use the end-of-string modes to detect that the GPIB
device has finished sending data.
A journalist is using a GPIB scanner to scan some pictures into his personal computer for
a news story. A GPIB cable runs between the scanner and the computer. He is using an
application written by an intern in the department who has read the scanner's instruction
manual and is familiar with the scanner's programming requirements. The following
steps correspond to the program flowchart in Figure 2-4.
1.
The application initializes the GPIB by bringing the interface board in the computer
online.
2.
The application sends a GPIB clear message to the scanner, initializing it to its
power-on defaults.
3.
The scanner needs to detect a delimiter indicating the end of a command. In this
case, the scanner expects the commands to be terminated with <CR><LF> (carriage
return,
\r
, and linefeed,
\n
). The application sets its end -of-string (EOS) byte to
<LF>. The linefeed code indicates to the scanner that no more data is coming, and is
called the end -of-string byte. It flags an end-of-string condition for this particular
GPIB scanner. The same effect could be accomplished by asserting the EOI line
when the command is sent.
4.
With the exception of the scan resolution, all the default settings are appropriate for
the task at hand. The application changes the scan resolution by writing the
appropriate command to the scanner.
5.
The scanner sends back information describing the status of the change resolution
command. This is a string of bytes terminated by the end -of-string character to tell
the application it is done changing the resolution.
6.
The application s tarts the scan by writing the scan command to the scanner.
7.
The application reads the scan data into the computer.
8.
As a cleanup step before exiting, the application returns the interface board to its
original state by taking it offline.