= Controlling GPIB devices through USB port = This page includes information on how to communicate with GPIB devices using USB port from a linux PC. == Using Agilent 82357B USB-GPIB interface from Linux == 82357B can be used from Linux using the linux-gpib driver. This section will explain how to install the driver and use it from python and other languages. === Installation === ===== What you need ===== Linux kernel source (2.6.8 or above) python, python-dev fxload (from linux-hotplug project) lsusb (usbutils package) Depending on your distribution, you may have to mount usbfs to /proc/bus/usb. (In Fedora, it is automatically mounted). If needed, you may want to add the following line to /etc/fstab {{{ usbfs /proc/bus/usb usbfs defaults 0 0 }}} ===== Installing linux-gpib driver ===== Before installing linux-gpib driver, create a group {{{gpib}}}, by {{{sudo vigr}}}. You want to add some users (e.g. controls) to {{{gpib}}} group so that those users can open GPIB devices. Download the latest version from http://linux-gpib.sourceforge.net/ Expand the archive and execute the following, {{{ ./configure --enable-python-binding --with-linux-srcdir=/lib/modules/2.6.24-19/build }}} where 2.6.24-19 should be replaced by your kernel version. {{{ make; sudo make install }}} should install the driver. ===== Installing firmwares ===== Download the proprietary firmwares from http://linux-gpib.sourceforge.net/firmware/ Expand the archive and copy {{{agilent_82357a/*.hex}}} to {{{/usr/share/usb/agilent_82357a/}}}. If the target directory does not exist, make it. ===== Configuration file and scripts ===== Put the following file in {{{/etc/}}}. [[attachment:gpib.conf]] Add the following lines to your {{{/etc/modprobe.conf}}} {{{ alias char-major-160 gpib_common alias char-major-160-0 agilent_82357a alias gpib0 agilent_82357a }}} Put the following files into somewhere in your PATH. [[attachment:initGPIB]] [[attachment:getgpibdata.py]] Be sure to set the permission of those files to executable. Change the group of /dev/gpib* to gpib and set the permission to group readable/writable. {{{ chown root:gpib /dev/gpib*; chmod ug+rw /dev/gpib* }}} === Usage === When you connect the GPIB-USB interface to your USB port, the kernel modules should be loaded automatically. If not, don't worry, the initGPIB script will load them. First, execute initGPIB script. You have to have {{{sudo}}} privilege to run the script as a normal user. This script will load the kernel modules, load the firmware twice (a work around for the buggy firmware of 82357B) and execute {{{gpib_config}}}. After initGPIB is completed, the "READY" LED on 82357B should be green. Now connect 82357B to 4395A analyzer. On the 4395A keypad, go to [Local]->[SET ADDRESSES]->[ADDRESS:4395] and set it to 17. Also set [ADDRESS: CONTROLLER] to 0. Do a measurement. Run {{{getgpibdata.py}}}. The command will output the data transfered from the analyzer into the standard output. So you can redirect it to a file like, {{{ %getgpibdata.py > data.txt }}} Then {{{data.txt}}} will look like this, {{{ +0.00000000000000E+000 +4.604457E-004 +6.25000000000000E+005 +3.845480E-005 +1.25000000000000E+006 +7.024327E-009 +1.87500000000000E+006 +1.066326E-009 +2.50000000000000E+006 +6.686992E-010 +3.12500000000000E+006 +2.618739E-010 ... }}} The first column is frequency, the second is, in this case, the magnitude of the CH1 spectrum. If you have CH2 active, you will have the third column. In the case of network analyzer mode, the second column is the real part of the transfer function and the third is the imaginary part. === How it works === GPIB devices are defined in {{{/etc/gpib.conf}}}. You have to specify the address of a device and assign an arbitrary name. The name is used later to search for a device in python scripts. {{{getgpibdata.py}}} is a simple python script. You can modify it to communicate with any kind of GPIB devices. Here is the programing manual for Agilent 4395A. [[attachment:4395A-GPIB-Manual.pdf]] == Alternative way (GPIB scripting in Python) == Software needed: * [[http://www.ni.com/visa/|National Instruments VISA driver]] (?) * [[http://sourceforge.net/projects/pyvisa/|Python GPIB library]] ([[http://superb-west.dl.sourceforge.net/sourceforge/pyvisa/PyVISA-1.1.linux-i686.tar.gz|PyVISA-1.1.linux-i686.tar.gz]]) * [[http://matplotlib.sourceforge.net/|Python MatPlotLib]] ([[http://superb-west.dl.sourceforge.net/sourceforge/matplotlib/matplotlib-0.90.0.tar.gz|matplotlib-0.90.0.tar.gz]]) * [[attachment:scripts.tar.gz]]