Programming GPIB Devices in VISA

VISA supports programming IEEE 488.1 and IEEE 488.2 devices, and includes complete device-level and board-level functionality.

For novice GPIB users, the VISA API presents a simple interface for device communication. Most GPIB devices allow you to set a primary address via either a DIP switch or via front panel selectors. This primary address is the same one used in the VISA resource string to viOpen(). The simplest and most common GPIB resource string is "GPIB::<primary address>::INSTR". Recall that the "INSTR" resource class informs VISA that you are doing instrument (device) communication. Most GPIB programs perform simple message-based transfers (write command, read response). For more information about VISA message-based functionality, see Message-Based Communication.

There are several VISA attributes specific to the GPIB INSTR resource. The VI_ATTR_GPIB_PRIMARY_ADDR and VI_ATTR_GPIB_SECONDARY_ADDR attributes are read-only, and these return the same values that were used in the resource string passed to viOpen(). If the specified device does not have a secondary address, that attribute query will succeed and return a value of –1. The attribute VI_ATTR_GPIB_READDR_EN controls whether each message to or from the same device will cause the driver to readdress the device. This attribute is true (enabled) by default, and disabling this attribute (setting it to false) may provide a slight performance increase by removing unnecessary bus-level readdressing to the same device. The attribute VI_ATTR_GPIB_UNADDR_EN controls whether the driver will follow each message to or from the specified device with untalk (UNT) and unlisten (UNL) commands. This attribute is false (disabled) by default, which is the most optimal setting. Changing the values of these attributes may be necessary for certain older non-IEEE 488.2-compliant devices.

More complex GPIB systems often include multiple GPIB controllers (or boards) and devices with both primary and secondary addresses. The canonical form of a complex GPIB instrument resource string is "GPIB<controller>::<primary address>::<secondary address>::INSTR". The controller number is the same as used in the GPIB configuration utility (MAX on Windows, the GPIB Control Panel applet on Macintosh, or ibconf on UNIX). If not specified, the controller number defaults to 0.

Since the NI-VISA and NI-488.2 APIs are very similar and both provide the same GPIB functionality, which should you choose? If you are already familiar with NI-488.2 and are programming only GPIB devices, then there is not a strong reason for you to change to VISA. NI-488.2 is supported in all major application development environments, including LabVIEW and Measurement Studio. However, if you have instruments with more than one type of port or connection available to them, then using VISA might be advantageous because you can use the same API regardless of the connection medium.

Finally, many modern instrument drivers rely on VISA for their I/O needs, so if you are using instrument drivers, then you need to at least install NI-VISA for them to be able to execute.