-
Notifications
You must be signed in to change notification settings - Fork 1
GPIB: Building an instrumentation lab with python libraries
First things first: you need a PCI-GPIB board or something similar and GPIB cable(s) to talk to your instrument(s).
We install the GPIB support, the visa files and then we test. We need a few tools to start this installation. Run this command in a terminal:
sudo apt install build-essential dkms linux-headers-$(uname -r)
The above command downloads the linux header files. You need them to build linux-gpib from the sources.
Download the linux-GPIB support files (kernel and user). Create 2 folders, unzip and copy the linux-gpib-kernel files in one folder and the linux-gpib-user files in the second one. cd to your kernel folder and type:
./configure
make
sudo make install
That will build and install the drivers in /usr/lib/modules/4.19.0-11-686-pae/gpib. Of course, the location depends on your distribution. Check it. You should see a list of drivers for different types of boards.
Load your driver. Mine is for a PCI-GPIB board, so I have to load tnt4882.ko. Check the doc to find out what you need!
sudo modprobe tnt4882
Check if your driver has loaded:
lsmod | grep tnt4882
So far so good. Next step: build and install the User space files. cd to your gpib-user folder and type:
./configure --sysconfdir=/etc PYTHON=python3.7
PYTHON=python3.7 is needed for me because I have different Python installs. Your system may be different. PyVISA needs at least Python 3.6 or higher. See https://pyvisa.readthedocs.io/en/latest/introduction/getting.html
Then type:
./configure
sudo make install
First install pip for python3 and check the installation:
sudo apt install python3-pip
pip3 --version
Install PyVISA and check:
pip3 install -U pyvisa
python3 -m visa info
That returns some important infos.
Install PyVISA-py and check again:
pip3 install -U pyvisa-py
python3 -m visa info
When finished, reboot your machine. Grab a coffee or whatever you like, we will test and connect to an instrument.
On my pc, the gpib configuration file gpib.conf is located in /etc and udev rules files are in /etc/udev/rules.d
You need to know where your files are located. This is pretty important to know where these files are. I spent some time dealing with this because I had another configuration file in another folder that was left from a previous install. You can check if you are using the right file. Just rename gpib.conf, and run the gpib_config utility. If that utility doesn't complain about a missing file, then you are probably editing the wrong file. Run:
sudo gpib_config --minor 0
Don't forget to rename it back...
Check if the group gpib has been created and that you belong to that group. Type:
cat /etc/group
If not, create that group and add yourself to it.
sudo groupadd gpib
sudo usermod -a -G gpib <your_username_here>
Check again:
cat /etc/group
Check if you have the right permissions on /dev/gpib0. Type:
ls -l /dev/gpib0
You should get something showing gpib as the group with root permissions.
crw-rw---- 1 root gpib 160, 0 Nov 15 15:11 /dev/gpib0
If not, then your rules have not been applied at boot time. Identify where these files are and copy them to /etc/udev/rules.d
This command should help you to find their location:
sudo find / -name "*gpib-generic.rules" -type f
Reboot.
It's now time to run a small script that will identify your instrument. It is called identifyme.py You run it like this:
python3 identifyme.py
It will return the name of your instrument if everything goes well...but you have to update your gpib.conf file to make it look like mine. See gpib.conf.
If you have another instrument, then you need to consult your manual.
Open gpib.conf, go to the device section and edit the name of the instrument so that it matches the name in identifyme.py. Then check the address of your instrument. I have set it to 6 (pad = 6). Check the identification command to query your device. I set it to "ID?". Then run:
sudo gpib_config --minor 0
And try your python script again. You may have to tweak the other parameters too (eos, set-reos, set-bin, set-xeos, set-eot)
Try the script getmyid.py. It's similar to identifyme.py. It should return the name of your device.
To test your Visa installation, download and run visa_test.py.