NI-488.2 routines directly adhere to the Controller sequences and protocols defined in the ANSI/IEEE Standard 488.2-1992. These routines function with any IEEE 488-compatible device. However, incorporating IEEE 488.2 devices in a GPIB system maximizes the potential of the NI-488.2 routines. Programming with NI-488.2 routines eliminates many of the confusing aspects of configuring the driver. For example, the NI-488.2 routines have little dependence on the settings of the driver as configured by the ibconfig function. NI-488.2 routines do not require a unit descriptor value as one of the parameters. Instead, the actual address of the GPIB device is used, which is more intuitive. Thus, the ibfind or ibdev functions are not used to open and initialize devices.
Using the flexibility of NI-488.2 routines, you can incorporate code to automatically configure and initialize the GPIB and its devices at the onset of a test program. In most cases, the addresses of those devices used in the NI-488.2 routines can be determined from routine calls in your application. One of the most important additions to the IEEE 488.2 standard is a requirement of Controllers to detect active listening devices on its bus. FindLstn, the NI-488.2 routine, determines which devices are listening on a GPIB. A GPIB can have up to 15 devices connected on the same bus, or more if you use bus expanders. Each of those devices must have a unique address in the range 0 through 30 (decimal), with an optional secondary address. FindLstn can easily detect the presence of devices on a range of known addresses. You do not need to know the address of each device in use because it is located by FindLstn. Finding all Listeners is the first step toward dynamic configuration and control of a GPIB system. After all the Listeners have been located, the address information that is returned can be used in other NI-488.2 routines. Further, after the Listeners are found, you can compare them with the Listeners you expect to find and respond accordingly. You can use this method to pinpoint malfunctioning devices, offline devices, or devices that might be incorrectly configured before any I/O is attempted. GPIB problems, if they occur, can be solved much sooner than before.
You can use the FindLstn routine in any GPIB application to find all active Listeners. An array of addresses that you want to test is passed as a parameter in the routine; the addresses of all the detected Listeners from that list are returned in another array. The first detected device address is placed in the first index of the array, the next detected device is placed in the second index, and so on. You can then pass the resulting array in other routines for communication to multiple devices, or use other routines to determine which device is at which address for use in single device communication routines.
The following code written in Microsoft Professional BASIC demonstrates the use of the FindLstn routine:
OPTION BASE 1
REM $INCLUDE: 'mbdecl.bas'
DIM instruments% (31)
DIM result% (30)
REM The first requirement in a NI-488.2 routine is to
REM initialize the bus by sending Interface Clear.
REM board% is the board index.
REM Create an array containing all the valid GPIB primary
REM This array will be used to determine the active Listeners
REM according to the IEEE 488.2 Find All Listeners protocol.
REM Do not test address 0, which is the default address of
REM the GPIB board, and which should always be listening.
REM The NOADDR constant terminates the list of addresses.
FOR k% = 1 to 30
instruments% (k%) = k%
instruments%(31) = NOADDR
REM Find all of the Listeners on the bus. The addresses of all
REM Listeners found will be stored in result%().
PRINT "Finding all Listeners on the bus..."
CALL FindLstn (0, instruments%(), result%(), 31)
IF ibsta% and EERR THEN
PRINT "GPIB Error Finding Listeners"
REM The ibcnt% global variable returns the number of
num.Listeners% = ibcnt%
PRINT "No. of instruments found = ", num.Listeners%
After the array of GPIB addresses is returned, it can be used in other NI-488.2 routines. For example, if you have three devices on the GPIB and each is IEEE 488.2-compatible. Using the SendList routine, you could send an identification query command to determine which specific devices are present. SendList sends the same message to multiple Listeners. In this case, the identification query *IDN? can be sent to all listening devices in a single application call. One of its parameters is an array of addresses that correspond to the devices to which you want to send the message. FindLstn and multiple device I/O automate your system because you can quickly determine which devices are online without having to query them separately. The following code is a continuation of the above application:
REM Now send the *IDN? command to each of the devices that you
REM found. The NLend constant tells the GPIB driver to append
REM the New Line character at the end of the string.
result%(ibcnt% + 1) = NOADDR
CALL SendList(0, result%(), "*IDN?", NLend)
IF ibsta% and EERR THEN
PRINT "Error Sending *IDN? Query"
Alternatively, you can use the Send routine to write a message to a single device address. Subsequent lines of code read each response of the device to the identification query and assign an identifier to each array index for use in subsequent routines. To continue with the example, use the Receive routine to read the identification information. The Receive routine reads data bytes from a single GPIB device.
REM Read the identification responses from the devices and
REM store them in reading$(), an array of strings. The
REM STOPend constant tells the driver to stop reading data
REM when it sees the END message.
DIM Reading(30) AS STRING * 20
FOR k% = 1 TO num.Listeners%
IF ibsta% and EERR THEN PRINT "Receive Error"
Device.Address% = result%(k%) and &HFF
PRINT "The instrument at address ";Device.Address%;
" is: ", reading$(k%)
In general, there are six defined groups of NI-488.2 routines that you can implement in an application: Simple Device I/O, Multiple Device I/O, Simple Device Control, Multiple Device Control, Bus Management, and Low-Level I/O. Each group represents a level of functionality. The Send and Receive routines are in the Simple Device I/O group. They can communicate only with a single device at a time. The SendList routine is in the Multiple Device I/O group, because it can transfer data to several GPIB devices. In addition to the I/O routines for devices, the Simple Device Control and Multiple Device Control groups handle high-level GPIB management. Routines in the Simple Device Control group perform clears, triggers, and serial polls to single device addresses. The routines used to configure devices for parallel polling and to conduct a single parallel poll are also in the Simple Device Control group. Similarly, the Multiple Device Control group can handle multiple devices at once. These routines include triggering, clearing, and serial polling multiple devices using a list of GPIB addresses. Additional routines find a device requesting service and control the remote and local programming states of GPIB devices.
The Bus Management group includes FindLstn, which detects active Listeners on the GPIB. Also included are routines which send interface clear, local lockout, remote with lockout state, and determine the state of the SRQ line. The Low-Level I/O group provides additional flexibility in the ways devices are addressed. Instead of addressing devices and transferring data bytes in a single routine call, you can use the Low-Level I/O routines to break up that operation into individual steps. One routine might address the devices to talk or listen, and another might transfer the data. These routines are useful if you have unusual situations in your system, such as transferring data between two Non-Controller devices.
The majority of the NI-488.2 routines do not require IEEE 488.2-compatible devices in your GPIB system. However, several routines specifically require IEEE 488.2 devices to execute properly. These routines send out specific data messages that compliant devices must understand: ResetSys and TestSys. ResetSys initializes an entire GPIB system in three stages. It first unaddresses all devices by sending Remote Enable (REN) and Interface Clear (IFC), which also establishes the GPIB board as Controller-In-Charge (CIC). In the second step, the GPIB interface sends Device Clear (DCL) to all connected devices. All 488.2-compatible devices are able to receive the reset message, which sends the *RST message to the devices contained in the address list. This initialization is specific to each device. TestSys causes devices represented in an address list to conduct self tests. You might want this at the onset of a test sequence, before actual I/O to the devices is initiated. The message that causes a device to self test has been specified by IEEE 488.2.