Using NI’s GPIB drivers in Qt

Using NI’s GPIB drivers in Qt

National Instruments DAQ drivers play nicely with Qt, but for some reason NI only provides a .obj file for the GPIB drivers and not a .lib file. Other people figured out how to get this working, but since the instructions are somewhat spread out across the internet I thought it would be nice to summarize the whole thing here. These instructions are for the MinGW build chain — things are somewhat simpler for the MSVCC version as one of my coworkers discovered, and I’ll add notes on that at a later date.

First, install the drivers and make sure you can see your GPIB instruments in NI MAX. Next, download the most recent version of the pexports tool, and stick it in a subfolder of your project, /GPIB. Then, following the instructions from MarkoSat:

  • Copy “gpib-32.dll” from your system folder and “ni488.h” from “c:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\include\” or similar and stick them in /GPIB.
  • Copy “dlltool.exe” from your MinGW folder to /GPIB
  • In /GPIB run pexports -h ni488.h gpib-32.dll > gpib.def
  • Next run dlltool -k -D gpib-32.dll -d gpib.def -l libgpib.a
  • Either add /GPIB to your project or just add “gpib-32.dll” and “libgpib.a” as libraries and stick “ni488.h” somewhere in the include path.
  • In your source make sure you include “windows.h” and “ni488.h”.  “windows.h” must be included first.

Once that’s done, you can work with the GPIB in largely the same way that you would in LabWINDOWS/CVI.  A simple Qt class that reads the voltage from a Signal Recovery 7265 lock-in amplifier is shown below.  (Ideally this would be further Qt-ified, it’s currently an almost direct copy of the equivalent c code.)

#ifndef LOCKIN7265_H
#define LOCKIN7265_H

class Lockin7265
    int address;
    int handle;
    void set_address(int ady);
    double get_x();


#endif // LOCKIN7265_H
#include "lockin7265.h"
#include "windows.h"
#include "ni488.h"


void Lockin7265::set_address(int ady) {
address = ady;
handle = ibdev(0, address, NO_SAD, T10s, 1, 0);

double Lockin7265::get_x()
char buff[100];
char *trash;
ibwrt (handle, const_cast<char*>("X."), strlen("X."));
ibrd (handle, &buff, 100);
return strtod(buff, &trash);
Comments are closed.