Skip to content

Instantly share code, notes, and snippets.

@ochococo
Last active February 10, 2026 19:36
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:

@montanaviking
Copy link

Hi,
I cannot get the installation to work if fails at step:
$ sudo gpib_config
[sudo] password for viking:
failed to configure boardtype: ni_pci
failed to configure board
main: Invalid argument
###############
running with strace gives:
#######################################################

$ sudo strace gpib_config
execve("/usr/local/sbin/gpib_config", ["gpib_config"], 0x7ffe1e164e30 /* 16 vars /) = 0
brk(NULL) = 0x625ba0c0f000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x797080eaf000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=84899, ...}) = 0
mmap(NULL, 84899, PROT_READ, MAP_PRIVATE, 3, 0) = 0x797080e9a000
close(3) = 0
openat(AT_FDCWD, "/usr/local/lib/libgpib.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=476688, ...}) = 0
mmap(NULL, 365016, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x797080e40000
mmap(0x797080e43000, 57344, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x797080e43000
mmap(0x797080e51000, 28672, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11000) = 0x797080e51000
mmap(0x797080e58000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x797080e58000
mmap(0x797080e5a000, 258520, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x797080e5a000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\243\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
fstat(3, {st_mode=S_IFREG|0755, st_size=2125328, ...}) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 2170256, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x797080c00000
mmap(0x797080c28000, 1605632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x797080c28000
mmap(0x797080db0000, 323584, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b0000) = 0x797080db0000
mmap(0x797080dff000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1fe000) = 0x797080dff000
mmap(0x797080e05000, 52624, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x797080e05000
close(3) = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x797080e3d000
arch_prctl(ARCH_SET_FS, 0x797080e3d740) = 0
set_tid_address(0x797080e3da10) = 79543
set_robust_list(0x797080e3da20, 24) = 0
rseq(0x797080e3e060, 0x20, 0, 0x53053053) = 0
mprotect(0x797080dff000, 16384, PROT_READ) = 0
mprotect(0x797080e58000, 4096, PROT_READ) = 0
mprotect(0x625b7ec1c000, 4096, PROT_READ) = 0
mprotect(0x797080ee7000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192
1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x797080e9a000, 84899) = 0
getrandom("\xb2\xec\xa8\xa7\xc2\x25\xc8\xcc", 8, GRND_NONBLOCK) = 8
brk(NULL) = 0x625ba0c0f000
brk(0x625ba0c30000) = 0x625ba0c30000
openat(AT_FDCWD, "/etc./gpib.conf", O_RDONLY) = 3
ioctl(3, TCGETS, 0x7fffbdbff220) = -1 ENOTTY (Inappropriate ioctl for device)
fstat(3, {st_mode=S_IFREG|0644, st_size=2838, ...}) = 0
read(3, "/*******************************"..., 8192) = 2838
read(3, "", 4096) = 0
read(3, "", 8192) = 0
ioctl(3, TCGETS, 0x7fffbdbfdd20) = -1 ENOTTY (Inappropriate ioctl for device)
close(3) = 0
openat(AT_FDCWD, "/dev/gpib0", O_RDWR) = 3
ioctl(3, _IOC(_IOC_WRITE, 0xa0, 0x27, 0x10), 0x7fffbdbff3c0) = 0
ioctl(3, _IOC(_IOC_WRITE, 0xa0, 0x18, 0x64), 0x7fffbdbff440) = -1 EINVAL (Invalid argument)
write(2, "failed to configure boardtype: n"..., 38failed to configure boardtype: ni_pci
) = 38
write(2, "failed to configure board\n", 26failed to configure board
) = 26
write(2, "main: Invalid argument\n", 23main: Invalid argument
) = 23
exit_group(-1) = ?
+++ exited with 255 +++
#################################################################

OS is Ubuntu 24.04
kernel is: 6.8.0-55-generic #57-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 12 23:42:21 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

gpib.conf file is at /etc/gpib.conf AND /usr/local/etc/gpib.conf

cat /etc/gpib.conf
interface {
minor = 0
board_type = "ni_usb_b"
pad = 0
master = yes
}
$ cat /usr/local/etc/gpib.conf

cat /usr/local/etc/gpib.conf

interface {
minor = 0
board_type = "ni_usb_b"
pad = 0
master = yes
}
$ lsusb
c$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 3923:709b National Instruments Corp. GPIB-USB-HS
Bus 001 Device 003: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Phone Data Cable
Bus 001 Device 004: ID 1058:2621 Western Digital Technologies, Inc. Elements 2621
Bus 001 Device 005: ID 3923:709b National Instruments Corp. GPIB-USB-HS
Bus 001 Device 006: ID 046d:0994 Logitech, Inc. QuickCam Orbit/Sphere AF
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 0547:139b Anchor Chips, Inc. USB3.0 Camera
#######################
$ $ lsmod | grep gpib
ni_usb_gpib 45056 0
gpib_common 57344 1 ni_usb_gpib
################################

Any ideas why the gpib_conf command won't run?
Thanks!
Phil

@mcgowanRochnu
Copy link

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!

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