Enter GPIB Primary and Secondary Addresses in LabVIEW

Updated Oct 31, 2023



  • GPIB Cable


  • LabVIEW


  • NI-488.2

This tutorial provides an overview on how to enter GPIB Primary and Secondary Addresses in LabVIEW using IEEE 488.1 and/or IEEE 488.2 functions.

IEEE 488.1 Functions

If you are using an IEEE 488.1 function such as GPIB Write or GPIB Read, the address takes the form of:

boardIndex: PAD + SAD

where the boardIndex is the index of bus that your board is controlling. (This is not necessarily the same as the board's primary address!) This usually corresponds to your board's interface name (for example, gpib0). PAD is the instrument's primary address, and SAD is the instrument's secondary address (if any).

For example, if your GPIB board is at PAD 0 and gpib2 is your board's interface name, the boardIndex is 2 (not 0). If your instrument is at PAD 5 and SAD 4, the address would be 2: 5 + 4 (not 2: 9!).

Quite often, a SAD is expressed as the secondary address plus 96, so (from the previous example) SAD 4 would be equivalent to SAD 100 (4 plus 96). Why the difference in notation? The secondary address is actually a value from 0 to 30, just like the primary address, but when you send address information across the GPIB, you send it as a byte (8 bits) of information: the first five bits make up the address, the next two bits are used to make Talker/Listener assignments, and the last bit is not used (so it is set to zero). For primary addresses, only one Talker/Listener bit is used (so a board or a device is either sending data or receiving data). But for secondary addresses, both Talker/Listener bits are set high (to indicate that it is a secondary address). As it happens, 96 decimal (60 hex) is the value of SAD 0 as expressed in this byte of information. All other secondary addresses are just 96 plus the SAD, for a total range of 96 to 126 for the SAD.

IEEE 488.2 Functions

If you are using an IEEE 488.2 function, such as Send or Receive, and you need to use a secondary address, you can use the MakeAddr function to create a "packed" address for you. The packed address consists of two bytes of information: a high byte (secondary address) and a low byte (primary address). You can express this packed address in hexadecimal, where the SAD is a value from 60 hex (96 decimal) to 7E hex (126 decimal) and the PAD is a value from 0 hex (0 decimal) to 1E hex (30 decimal).

For example, using the previous example (the GPIB board is gpib2 at PAD 0, the instrument is at PAD 5 and SAD 4), the packed address would be 0x6405 (high byte = 60 hex + 04 hex, low byte = 05 hex). The board information is a separate input, used in the functions themselves. For example, the Send function has a bus input that corresponds to the boardIndex mentioned above. The bus for gpib2 is 2 (not 0 -- that is the PAD).

Note: Although the SAD is converted to a value from 96 to 126, the actual secondary address input for the MakeAddr function takes a value from 0 to 30.