Chandigarh,India
jithinbp@gmail.com
contents
Instruments used
1. Install Debian 5.0.2 (use only one DVD, disconnect network during installation ..select the
'configure later' option)
After installation
#gedit /etc/apt/sources.list
Save the file and run the following commands on a root terminal
#apt-get update
#apt-get install debhelper
#apt-get install module-assistant
#apt-get install gpib-modules-source
#module-assistant prepare
#module-assistant auto-install gpib
#modprobe ni_usb_gpib //shouldn't fetch you an error .. this function loads the module
debian:/var/www# lsusb
Bus 002 Device 005: ID 3923:709b National Instruments Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 046d:089d Logitech, Inc.
Bus 001 Device 003: ID 04f2:0760 Chicony Electronics Co., Ltd
Bus 001 Device 002: ID 04ca:0030 Lite-On Technology Corp.
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Add the following line to /etc/apt/sources.list
#apt-get update
#apt-get install python-gpib
#gpib_config --minor 0
#gedit /etc/gpib.conf
/***********************************************************************
GPIB.CONF IEEE488 library config file
-------------------
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 = "violet" /* 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 */
/* pci_bus and pci_slot can be used to distinguish two pci boards supported by the same driver */
/* pci_bus = 0 */
/* pci_slot = 7 */
/* This is how you might set up a pcIIa board on /dev/gpib1, uncomment to use. */
/*******************
interface {
minor = 1
board_type = "pcIIa"
pad = 0
sad = 0
timeout = T3s
eos = 0x0a
set-reos = yes
set-bin = no
base = 0x2e1
irq = 7
dma = 1
master = yes
}
*********************/
/* Now the device sections define the device characteristics for each device.
* These are only used if you want to open the device using ibfind() (instead
* of ibdev() )
*/
device {
minor = 0 /* minor number for interface board this device is connected to */
name = "multi" /* device mnemonic */
pad = 16 /* The Primary Address */
sad = 0 /* Secondary Address */
device {
minor = 0
name = "pcs"
pad = 12
sad = 0
}
---------------------------------------
i added two devices .. both conected to the same gpib usb dongle from National Instruments
and a Keithley 224 programmable current source with primary address set as 12
--------------------------------------
# cd usr/src/modules/gpib/
# ./configure
# make //this program compiles all programs in the diractory according to set of rules
defined in a Makefile
//it also does linking and all requisite steps
#cd examples
this directory contains example program ibtest.c which has been compiled by the make command
to use this interactive program
# ./ibtest
open your device , set the address and write to it
in my case .. example commands i wrote to it using ibtest were
'w' to use write to device
:FUNC 'res'
this changed mode to measure two probe resistance
'w' again to write a second command
:DATA?
'r' to read
read 100 bytes
:w
enter a string to send to your device: :FUNC 'res'
sending string: :FUNC 'res'
ibcnt = 12
------------------------
:w
enter a string to send to your device: :DATA?
sending string: :DATA?
:r
enter maximum number of bytes to read [1024]: 50
trying to read 50 bytes from device...
received string: '+3.30753E+03NOHM,+140.831378SECS,+03850RDNG#,00EXT'
Number of bytes read: 50
gpib status is:
ibsta = 0x100 < CMPL >
iberr= 0
ibcnt = 50
----------------------------
:q
debian:/usr/src/modules/gpib/examples#
that was about using the included example file ibtest.c
#./configure
#make
#rm /lib/modules/2.6.26-1-686/gpib
#make install
#cd examples
create your file .. say ex.c
write the code by reffering to ibtest.c and instrument documentation
compile
#gcc -o ex ex.c -lgpib //#gcc -o <object_file_name> <source_file_name> -lgpib
run
# ./ex
----------------------------------
configuring remote access using mod_python and apache web server
install apache and mod-python using synaptic package manager if not already installed
#apache2ctl restart
# gedit /etc/apache2/sites-available/default
<Directory /var/www/py>
AddHandler mod_python .py
PythonHandler hello
PythonDebug On
</Directory>
online help
http://modpython.org/live/mod_python-3.2.2b/doc-html/inst-testing.html
http://g2pc1.bu.edu/~qzpeng/gpib/manual/INSTALL_gpib
def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK
save it and restart apache
#apache2ctl restart
Hello World!
--------------------------------
//example.py
--------------------------
import Gpib
from Tkinter import *
root=Tk()
def readres():
a=Gpib.Gpib('multi')
a.clear()
a.write(":FUNC 'res'")
a.write(":DATA?")
data=a.read(8)
print data
b=Button(root,text='read value',command=readres)
b.pack()
root.mainloop()
------------------------------
the functions written to the instrument are specific to KEITHLEY 2001 multimeter
the main steps are
creating the instance
a=Gpib.Gpib('multi') //'multi' refers to the name of the device specified in /etc/gpib.conf
and
a.clear()
the instance <a> ,to the class Gpib() contains all necessary functions
modifying mptest.py to get readings from the KEITHLEY 2001 multimeter on a web browser
firstly, permissions must be set so a normal user rather than administrator(root) can use it
//read resistance.py
----------------------------------------------------
def do_read():
import Gpib
a=Gpib.Gpib('multi')
if a == None:
return 'Accessing Error'
a.clear()
a.write(":FUNC 'res'")
a.write(":DATA?")
data=a.read(8)
ss = 'resistance = ' + data + 'ohm'
return ss
def handler(req):
req.content_type = 'text/plain'
result = do_read()
req.write(result)
return apache.OK
-------------------------------------------
save it ... open the web browser
"http://localhost/mptest.py"