A third method for configuring devices is to dynamically configure them within the application program using special configuration functions. As described earlier, configuring a GPIB system requires knowledge of the bus and of the devices to which it is connected. Developers of application software can dynamically configure the driver so that novice users do not have to understand or edit IBCONF. This method is also ideal for running many different system configurations with the same GPIB interface board. Configuration changes made in the program only apply while the program is running. Upon termination, the configuration parameters are restored to their original settings. This method of configuration is not only more efficient, but also makes it very easy, because it comes in the form of subroutine function calls.
The IBCONFIG Function
By using the most powerful configuration function, ibconfig, you can dynamically configure all the software parameters found in IBCONF by simply adding ibconfig function calls to the application program. You can ensure that the driver is configured correctly regardless of the settings in IBCONF. The configuration parameters of ibconfig can be divided into two groups: board parameters and device parameters. Board parameters, for example, enable/disable hardware interrupts or enable/disable automatic serial polling. Device parameters can enable/disable repeat addressing.
You can also select primary and secondary addressing, timeout, and End-Of-String termination using ibconfig. However, the traditional NI-488 configuration functions ibpad (change primary address), ibsad (change secondary address), ibtmo (change timeout setting), ibeos (set End-Of-String character), and ibeot (set END termination message) are still supported. The following portion of code shows how the ibconfig function is used.
REM QuickBASIC 4.5 Example
REM The following code sets up a device for GPIB operation.
REM $INCLUDE: 'qbdecl.bas'
CALL ibfind ("dev1", dev%)
REM Change primary address to 7.
option% = IbcPAD:value% = 7
CALL ibconfig(dev%, option%, value%)
REM Change timeout to 10 seconds.
option% = IbcTMO:value% = 13
CALL ibconfig (dev%, option%, value%)
The IBLN Function
The ibln function checks for a Listener at the specified address. This is similar to the NI-488.2™ routine FindLstn, except that the parameter is a single device address, not an array of addresses. ibln is useful for scanning several addresses to find out which Listeners are on the bus. Once you know what the address is, you can use ibconfig to change the primary address of that device in the driver.
The following portion of QuickBASIC code scans for Listeners at all GPIB primary addresses (with no secondary addresses) on the bus and reports which devices were found.
REM $INCLUDE: 'qbdecl.bas'
cnt% = 0
REM The following call opens dev1 as a generic device.
REM You need a unit descriptor to call ibln.
CALL ibfind("dev1", dev%)
REM Because you are not looking for secondary addresses, set
REM the sad parameter to 0. sad% = 0
REM Now scan the 30 possible primary addresses. Notice that
REM you are not checking address 0 because it is the default
REM address of the GPIB Controller, which should always be
FOR i% = 1 to 30
CALL ibln(dev%, i%, sad%, listen%)
REM Check the response to see if a Listener is present at the
REM address specified by i%. If a device is listening, save
REM the address into the array Device%(), which is a listing
REM of all active Listeners.
REM Increment the count as each Listener is found.
IF listen% = 1 THEN
Device%(cnt%) = i%
cnt% = cnt% + 1
REM Now print out the active addresses.
PRINT "Devices are present at the following addresses"
FOR j% = 0 to cnt% - 1
PRINT "A device is at GPIB Address "; Device%(j%)
The IBDEV Function
In traditional NI-488 applications, the ibfind function is used to open devices for communication. ibfind returns a number (the unit descriptor) so GPIB calls can be made to that device. To use ibfind, however, the device name must be pre-configured in IBCONF, otherwise, ibfind will fail. As you can see, this is a shortcoming if you do not know the device name.
By using the ibdev function instead of the ibfind function, you can open and initialize a device without knowing its name. ibdev is similar to ibfind, except you do not pass a device name as one of the arguments in the function. ibdev simply opens the first unopened user-configurable device that it finds and returns a unit descriptor that is used in ibconfig, ibln, and all other device-level calls. After calling ibdev to obtain a unit descriptor, you may also need to call ibconfig to configure communication characteristics not configured using ibdev.
An example of how to use ibdev is shown below.
REM bd.index% is either 0 for gpib0 or 1 for gpib1.
bd.index% = 0
REM pad% is the primary address of the device you wish to
REM open. Suppose that in the above program, you determine
REM that there was one listening device at address 7.
pad% = Device%(0) : sad% = 0
REM For the other parameters that must be specified, set
REM the timeout to 10 seconds, enable the END message on
REM writes, and disable any EOS termination.
tmo% = 13 : eot% = 1 : eos% = 0
REM When calling ibdev, the value returned in ud% is the
REM unit descriptor.
CALL ibdev(bd.index%, pad%, sad%, tmo%, eot%, eos%, ud%)