Skip to content

Instantly share code, notes, and snippets.

@ochococo
Last active May 9, 2026 05:01
Show Gist options
  • Select an option

  • Save ochococo/8362414fff28fa593bc8f368ba94d46a to your computer and use it in GitHub Desktop.

Select an option

Save ochococo/8362414fff28fa593bc8f368ba94d46a to your computer and use it in GitHub Desktop.
National Instruments GPIB-USB-HS via PyVISA on UBUNTU.md

National Instruments GPIB-USB-HS + PYVISA on Ubuntu

LINUX-GPIB

Install depedencies:

sudo apt-get install tk-dev build-essential texinfo texi2html libcwidget-dev libncurses5-dev libx11-dev binutils-dev bison flex libusb-1.0-0 libusb-dev libmpfr-dev libexpat1-dev tofrodos subversion autoconf automake libtool mercurial

Checkout the LINUX-GPIB to user home dir:

cd ~
svn checkout svn://svn.code.sf.net/p/linux-gpib/code/trunk linux-gpib-code

Install the kernel part:

cd ~/linux-gpib-code/linux-gpib-kernel
make
sudo make install

Instal the user part:

cd ~/linux-gpib-code/linux-gpib-user
sudo make install

Check if USB dongle is connected:

lsusb | grep GPIB

expected result:

Bus 001 Device 006: ID 3923:709b National Instruments Corp. GPIB-USB-HS

Load kernel module:

sudo modprobe ni_usb_gpib

Update cache for linker

sudo ldconfig

Check if kernel module loaded:

lsmod | grep gpib

expected result:

ni_usb_gpib            36864  0
gpib_common            45056  1 ni_usb_gpib

Create config file

interface {
        minor = 0
        board_type = "ni_usb_b"
        pad = 0
        master = yes
}

File location for Ubuntu:

/usr/local/etc/gpib.conf

Test GPIB configuration:

sudo gpib_config

expected result:

no output, no error

Try to communicate with the device:

sudo ibtest
  • d ENTER,
  • address of your instrument ex. 3
  • w ENTER.
  • type *IDN? ENTER,
  • r ENTER
  • 100 ENTER

Expected result:

Example: KEITHLEY INSTRUMENTS INC.,MODEL 2000,0000,A05 /A02

If that works it means that linux-gpib can talk to the adapter and instrument. Success.

Python3

Install Python3 depedencies

sudo apt-get install python3-dev python3-distutils python3-pip python3-setuptools

Install Python bindings

cd linux-gpib-code/linux-gpib-user/
cd language/python/
sudo python3 setup.py install

Test script

~/testgpib.py

import Gpib
# X is your interface number (usually 0)
# Y is your instrument address (should be configured on the device)
inst = Gpib.Gpib(X,Y) 
inst.write("*IDN?")
print(inst.read(100))
python3 ~/testgpib.py

expected result:

Example: KEITHLEY INSTRUMENTS INC.,MODEL 2000,0000,A05 /A02

PyVISA

Install pyvisa

pip3 install pyvisa

Install pyvisa-py backend

pip3 install pyvisa-py

Install gpib-ctypes

pip3 install gpib-ctypes

Verify configuration

python3 -m visa info

Expected result:

(...)
Backends:
   ni:
      (not important)
   py:
      Version: X.X.X
      GPIB INSTR: Available via Linux GPIB (b'X.X.X r[XXXX]')
      GPIB INTFC: Available via Linux GPIB (b'X.X.X r[XXXXX]')

Test script

~/testvisa.py

import pyvisa
resources = pyvisa.ResourceManager('@py')
# X means your instrument address
k2000 = resources.open_resource('GPIB::X::INSTR')
print(k2000.query('*IDN?'))
python3 ~/testvisa.py

expected result:

Example: KEITHLEY INSTRUMENTS INC.,MODEL 2000,0000,A05 /A02

Sources

While compiling this instruction I used different sources including:

@lumipallero
Copy link
Copy Markdown

Thank you for sharing this! Following your instructions, plus some fixes along the way, I successfully deployed a National Instruments GPIB-USB-HS on Ubuntu 24.04 LTS, reading input from three Keithley 2000 multimeters. This was working on kernel 6.14.0-37-generic #37-24.04.1-Ubuntu, and any later kernels until update to 6.17.0-14-generic #14-24.04.1-Ubuntu. With this kernel, testgpib.py fails with:

libgpib: ibBoardOpen failed to open device file /dev/gpib0
libgpib: No such file or directory
libgpib: error in is_cic()!
Traceback (most recent call last):
  File "/home/instructor/Desktop/workingSC_2026/testgpib.py", line 5, in <module>
    inst = Gpib.Gpib(0,14)
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/gpib-1.0-py3.12-linux-x86_64.egg/Gpib.py", line 26, in __init__
    self.id = gpib.dev(name, pad, sad, timeout, send_eoi, eos_mode)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gpib.GpibError: dev() error: Bad file descriptor (errno: 9)

I obliterated the original installation and started over, which yields a new error that I did not encounter in my initial installation, and I have not yet found a fix for. This is in the earliest make command in the instructions:

~/linux-gpib-code/linux-gpib-kernel$ make
make -C /lib/modules/`uname -r`/build V=0 modules \
	M="/home/instructor/linux-gpib-code/linux-gpib-kernel/drivers/gpib" \
	GPIB_TOP_DIR=/home/instructor/linux-gpib-code/linux-gpib-kernel \
	CONFIG_GPIB_ISA="" \
	GPIB_CONFIG_PCMCIA="0" \
	HAVE_DEV_OF_NODE= \
	GPIB_CONFIG_KERNEL_DEBUG=0
make[1]: Entering directory '/usr/src/linux-headers-6.17.0-14-generic'
make[2]: Entering directory '/home/instructor/linux-gpib-code/linux-gpib-kernel/drivers/gpib'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: x86_64-linux-gnu-gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
  You are using:           gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
  CC [M]  agilent_82357a/agilent_82357a.o
In file included from /usr/src/linux-headers-6.17.0-14-generic/include/linux/uprobes.h:18,
                 from /usr/src/linux-headers-6.17.0-14-generic/include/linux/mm_types.h:16,
                 from /usr/src/linux-headers-6.17.0-14-generic/include/linux/mmzone.h:22,
                 from /usr/src/linux-headers-6.17.0-14-generic/include/linux/gfp.h:7,
                 from /usr/src/linux-headers-6.17.0-14-generic/include/linux/umh.h:4,
                 from /usr/src/linux-headers-6.17.0-14-generic/include/linux/kmod.h:9,
                 from /usr/src/linux-headers-6.17.0-14-generic/include/linux/module.h:18,
                 from /home/instructor/linux-gpib-code/linux-gpib-kernel/compat/include/linux/module.h:61,
                 from agilent_82357a/agilent_82357a.c:23:
agilent_82357a/agilent_82357a.c: In function ‘agilent_82357a_timeout_handler’:
/home/instructor/linux-gpib-code/linux-gpib-kernel/compat/include/linux/timer.h:50:9: error: implicit declaration of function ‘from_timer’; did you mean ‘mod_timer’? [-Werror=implicit-function-declaration]
   50 |         from_timer(var, callback_timer, timer_fieldname)
      |         ^~~~~~~~~~
agilent_82357a/agilent_82357a.c:51:44: note: in expansion of macro ‘COMPAT_FROM_TIMER’
   51 |         agilent_82357a_private_t *a_priv = COMPAT_FROM_TIMER(a_priv, t, bulk_timer);
      |                                            ^~~~~~~~~~~~~~~~~
agilent_82357a/agilent_82357a.c:51:73: error: ‘bulk_timer’ undeclared (first use in this function)
   51 | ent_82357a_private_t *a_priv = COMPAT_FROM_TIMER(a_priv, t, bulk_timer);
      |                                                             ^~~~~~~~~~

/home/instructor/linux-gpib-code/linux-gpib-kernel/compat/include/linux/timer.h:50:41: note: in definition of macro ‘COMPAT_FROM_TIMER’
   50 |         from_timer(var, callback_timer, timer_fieldname)
      |                                         ^~~~~~~~~~~~~~~
agilent_82357a/agilent_82357a.c:51:73: note: each undeclared identifier is reported only once for each function it appears in
   51 | ent_82357a_private_t *a_priv = COMPAT_FROM_TIMER(a_priv, t, bulk_timer);
      |                                                             ^~~~~~~~~~

/home/instructor/linux-gpib-code/linux-gpib-kernel/compat/include/linux/timer.h:50:41: note: in definition of macro ‘COMPAT_FROM_TIMER’
   50 |         from_timer(var, callback_timer, timer_fieldname)
      |                                         ^~~~~~~~~~~~~~~
agilent_82357a/agilent_82357a.c: In function ‘agilent_82357a_send_bulk_msg’:
agilent_82357a/agilent_82357a.c:121:25: error: implicit declaration of function ‘del_timer_sync’ [-Werror=implicit-function-declaration]
  121 |                         del_timer_sync(&a_priv->bulk_timer);
      |                         ^~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[5]: *** [/usr/src/linux-headers-6.17.0-14-generic/scripts/Makefile.build:287: agilent_82357a/agilent_82357a.o] Error 1
make[4]: *** [/usr/src/linux-headers-6.17.0-14-generic/scripts/Makefile.build:556: agilent_82357a] Error 2
make[3]: *** [/usr/src/linux-headers-6.17.0-14-generic/Makefile:2016: .] Error 2
make[2]: *** [/usr/src/linux-headers-6.17.0-14-generic/Makefile:248: __sub-make] Error 2
make[2]: Leaving directory '/home/instructor/linux-gpib-code/linux-gpib-kernel/drivers/gpib'
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.17.0-14-generic'
make: *** [Makefile:10: all] Error 2

Anyone out there with a similar configuration? Thanks in advance for any assistance!

The files from checkout have commands that do not work with current kernel. Replacing the files directly from Linux GPIB project git (https://sourceforge.net/p/linux-gpib/git/ci/master/tree/) and then following the tutorial worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment