First of all we moved away from ?LabView. It literally generates a spaghetti code, and its almost impossible to do advance data processing with it. To its defense generally it is very easy to just grab data.
Since we use Matlab for almost all data acquisition and processing it is mandatory to make it work on Linux. Below are the general steps to make it working with Debian Linux.
Step 1 install Matlab, this is relatively easy. Though from 2013 they stop supporting 32 bits platforms. How to make gpib aware instruments available for Matlab
Step 2 Attempt to install NI VISA. There are a few distributions supported, but Debian is not one of them.
- Step 2a Curse this fallen world and abandon this idea. Move on.
Turns out that in Linux life is easy. There is no need for 300 MB beast visa installation, which essentially provides a serial port drivers and gpib driver. Serial ports are built in Linux kernel, the gpib driver need to be installed, see more about it later in the text. Though gpib is very useful and bullet proof, this is interface from the 1960 developed by HP. There are other ways to do it more conveniently, think USB.
Many modern devices, provide serial interface (or something equivalent) via USB hardware. The prominent example of it would be Rigol scopes, spectrum analyzers, etc. If you plug them to the Linux machine, you will see a new device in the /dev/
directory with name starting with usbtmc
. This is actually analogous to a serial port, one can write and read from it as from any other files. We will make one more optional step and make a symbolic link with a bit more descriptive name, though still somewhat cryptic to match VISA naming scheme.
We will make udev rule file, which will create mentioned above symbolic links automatically, when we plug a Rigol device into the USB or on start up of the computer. Create a file under /etc/udev/rules.d/
with an arbitrary name, for example 99-rigol-equipment.rules
with the following content (note below the lines might wrap, make one long line for text starting with KERNEL)
#Rigol products to visa compatible names
#
# Rigol's USB connected device present themselves as /dev/usbtmc*
# Rules below links /dev//dev/0x1ab1::0x04ce::DS1ZA172215698 -> usbtmc1
# which gives it more human readable name and allow to do VISA name to device name translation
# Rigol scopes: for example DS1054z
KERNEL=="usbtmc[0-9]*", ATTRS{idVendor}=="1ab1", OWNER="plugdev", GROUP="plugdev", MODE="0660", SYMLINK+="Rigol$number 0x$attr{idVendor}::0x$attr{idProduct}::$attr{serial}"
# Rigol signal generators: for example DG1022
KERNEL=="usbtmc[0-9]*", ATTRS{idVendor}=="0400", OWNER="plugdev", GROUP="plugdev", MODE="0660", SYMLINK+="Rigol$number 0x$attr interface {
minor = 0 /* board index, minor = 0 uses /dev/gpib0, minor = 1 uses /dev/gpib1, etc. */
board_type = "ni_usb_b" /* type of interface board being used */
name = "usb-hs" /* optional name, allows you to get a board descriptor using ibfind() */
pad = 0 /* primary address of interface */
sad = 0 /* secondary address of interface */
timeout = T3s /* timeout for commands */
eos = 0x0a /* EOS Byte, 0xa is newline and 0xd is carriage return */
set-reos = yes /* Terminate read if EOS */
set-bin = no /* Compare EOS 8-bit */
set-xeos = no /* Assert EOI whenever EOS byte is sent */
set-eot = yes /* Assert EOI with last byte on writes */
master = yes /* interface board is system controller */
}
device {
minor = 0 /* minor number for interface board this device is connected to */
name = "HP8596E" /* device mnemonic */
pad = 18 /* The Primary Address */
sad = 0 /* Secondary Address, 0 means disabled*/
eos = 0xa /* EOS Byte */
set-reos = no /* Terminate read if EOS */
set-bin = no /* Compare EOS 8-bit */
}{idVendor}::0x$attr{idProduct}::$attr{serial}"
Once you did it, reload the udev service.
Installing the gpib driver
If you need the gpib driver read below.
- Install linux-gpib
- If you run deb package supported distributions, it is your lucky day: I made Debian packages. The official Debian distribution somehow stopped supporting it quite a few major version ago.
- Well, I actually took the debian souce package from http://www.heklatech.com/debian/source/ and recompile. The lead to this page was found at http://www.heklatech.com/gpib/gpib.html
- additionally, I had to modify libgpib-perl.install file to match compiled files and the package generated with jessie and other versions of Debian.
- add the following to your sources.list or sources.list.d/
deb http://physics.wm.edu/~evmik/debian stretch-evmik/ deb-src http://physics.wm.edu/~evmik/debian stretch-evmik/
- If you run deb package supported distributions, it is your lucky day: I made Debian packages. The official Debian distribution somehow stopped supporting it quite a few major version ago.
or
deb http://physics.wm.edu/~evmik/debian jessie-evmik/
deb-src http://physics.wm.edu/~evmik/debian jessie-evmik/
or
deb http://physics.wm.edu/~evmik/debian wheezy-evmik/
deb-src http://physics.wm.edu/~evmik/debian wheezy-evmik/
- run: apt-get update
- run: apt-get install libgpib-bin libgpib-dev
- note libgpib-dev will be crucial for Matlab interface to work with gpib
- now we need the drivers
- run: apt-get install gpib-modules-source
- run: sudo m-a a-i gpib-modules-source
- this will compile gpib modules and put them in the proper place. Note that you might need kernel headers and sources for modules assistant to succeed
- edit /etc/gpib.conf to reflect your situation. Ours look like this for gpib-usb-hs NI board
/* This section configures the configurable driver characteristics
* for an interface board, such as board address, and interrupt level.
* minor = 0 configures /dev/gpib0, minor = 1 configures /dev/gpib1, etc.
*/
interface {
minor = 0 /* board index, minor = 0 uses /dev/gpib0, minor = 1 uses /dev/gpib1, etc. */
board_type = "ni_usb_b" /* type of interface board being used */
name = "usb-hs" /* optional name, allows you to get a board descriptor using ibfind() */
pad = 0 /* primary address of interface */
sad = 0 /* secondary address of interface */
timeout = T3s /* timeout for commands */
eos = 0x0a /* EOS Byte, 0xa is newline and 0xd is carriage return */
set-reos = yes /* Terminate read if EOS */
set-bin = no /* Compare EOS 8-bit */
set-xeos = no /* Assert EOI whenever EOS byte is sent */
set-eot = yes /* Assert EOI with last byte on writes */
master = yes /* interface board is system controller */
}
device {
minor = 0 /* minor number for interface board this device is connected to */
name = "HP8596E" /* device mnemonic */
pad = 18 /* The Primary Address */
sad = 0 /* Secondary Address, 0 means disabled*/
eos = 0xa /* EOS Byte */
set-reos = no /* Terminate read if EOS */
set-bin = no /* Compare EOS 8-bit */
}
- sudo chmod o+rw /dev/gpib*
- a bit unsecure since everyone can write to gpib devices
Matlab gpib related wrappers
- visit matlab-gpib wrappers
- well google probably will discontinue its support soon, use back up link with several custom examples at https://github.com/evgmik/matlab-gpib
- copy this code to the matlab dir with the script working with gpib
execute once
mex gpib_function.c dispatch.c -lgpib
- this is where libgpib0-dev becomes handy and you obviously need gcc installed
- this makes available matlab commands like: read, write, query, and so on aware of gpib interface
note that our gpib.conf defines HP8596E, so we can execute
obj1 = lgpib('HP8596E');
- once we have the object of device the rest of the commands works exactly like they do with Windows version talking via NI drivers. I.e. the following will work just fine
query(obj1, '*IDN?')
- as well as write, read, and lower level ib* commands