Introduction

The linux-gpib package is a set of software that supports programmatic access to IEEE-488 General Purpose Interface Bus compliant devices and instruments via a number of supported boards. Boards are adapters or interface cards that permit a computer to be connected to a GPIB bus. Typical instruments are test and measurement instruments such as signal generators, volt meters, oscilloscopes and spectrum analysers. There are also GPIB capable devices such as printers, plotters and digitizing tablets.

The linux-gpib package is comprised of 2 parts: user part and kernel part. The user part contains

The kernel part contains the drivers for the different supported boards. See Supported Hardware. The kernel part is provided for installations that do not have built-in kernel support for the drivers.

An IEEE-488 compliant board can drive a GPIB bus with up to 15 devices attached. Each device on the bus, as well as the board connected to it, must be assigned a unique primary address ranging from 0 to 30. GPIB addresses of devices or instruments are assigned by setting DIP switches or via the front panel. The GPIB address of boards are assigned via software configuration (see Configuration). Some boards also support secondary addressing. This feature is very rarely needed.

The software supports the use of multiple boards in one system. Some boards can also function as devices. Each board is assigned an identifier called a minor by which it is referenced in the sotfware functions. Devices are referenced programmatically by a device descriptor which is obtained with the ibdev() function by specifying the minor of the board of the bus to which they are connected. Board descriptors and device descriptors can also be obtained with the ibfind() function by specifying their name as defined in the configuration file. The minor can also be used directly as a board descriptor. Board descriptors are only needed in advanced applications requiring fine control over the bus such as emulating a device or managing the bus state. When using a device descriptor for I/O the library automatically handles the low level functions such as configuring the device to talk or listen on the bus.

Here is simple programme to read the identification string of a device. The descriptor is obtained with ibfind() by the name voltmeter defined in the configuration file. Error handling has been omitted for clarity.



#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <gpib/gpib_user.h>
#include <gpib/ib.h>

int main() {
  int ud;                /* descriptor for the device      */
  char *id = "*IDN?\n";  /* string to request id of device */
  uint8_t buf[256];      /* buffer for response            */

  ud = ibfind("voltmeter");      /* obtain descriptor by name   */
  ibwrt(ud, id, strlen(id));     /* send request-id string      */
  ibrd(ud, buf, 256);            /* read response               */
  buf[ibcnt] = 0;                /* null terminate the response */
  printf("Device id: %s\n", buf);
  return 0;
}

Here is the same programme using ibdev() to access a device with a primary GPIB address of 7 attached to the bus connected to a board configured with minor 0. This provides more control over the parameters or defaults in the configuration file if present.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <gpib/gpib_user.h>
#include <gpib/ib.h>

int main() {
  int minor = 0;         /* minor of board                 */
  int pad = 7;           /* primary GPIB address of device */
  int sad = 0;           /* no secondary address           */
  int timeout = T300ms;  /* set timeout to 300 millseconds */
  int eoi = 1;           /* send EOI with last byte        */
  int eos = 0;           /* no end of string character     */
  int ud;                /* descriptor for the device      */
  char *id = "*IDN?\n";  /* string to request id of device */
  uint8_t buf[256];      /* buffer for response            */

  ud = ibdev(minor, pad, sad,    /* obtain device descriptor    */
	     timeout, eoi, eos); 
  ibwrt(ud, id, strlen(id));     /* send request-id string      */
  ibrd(ud, buf, 256);            /* read response               */
  buf[ibcnt] = 0;                /* null terminate the response */
  printf("Device id: %s\n", buf);
  return 0;
}