Anda di halaman 1dari 11

#Author : Jithin B.P.

          IISER mohali,

          Chandigarh,India

contact the author: 

          jithinbp@gmail.com

#Distributed under GNU General Public License

How to get GPIB drivers installed on Debian Lenny

contents

 Installing debian OS on your system


 configuring the network
 downloading requisite packages
 configuring linux GPIB and installing drivers necessary
 editing /etc/ gpib.conf
 Running test programs in C language
 Making your own programs and compiling them in C
 configuring remote access using mod_python publishing tool and Apache web server 
 Gpib using python

        

Instruments used

    KEITHLEY 2001 multimeter

    PHOENIX _Physics With Homemade Equipment And Innovative Experiments

 //type anything followed by '#' onto a root terminal

1. Install Debian 5.0.2 (use only one DVD, disconnect network during installation ..select the
'configure later' option)

    After installation

->configure the network


system->administration->network configure the network
open synaptic package manager    //from the same menu
    
    settings->preference->network // configure it , do not forget authentication setting if any
->Open a root Terminal

#gedit /etc/apt/sources.list

a) Uncomment  the following lines(i.e. remove the preceding # symbol)

deb http://volatile.debian.org/debian-volatile lenny/volatile main contrib


deb-src http://volatile.debian.org/debian-volatile lenny/volatile main contrib

c) Add the following lines to the file(taken from http://gudjon.org/gpib/gpib.html )

deb-src http://195.198.146.229/debian/ source/


deb http://195.198.146.229/debian/ i386/
deb http://195.198.146.229/debian/ amd64/

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

#lsmod (to test the result)

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

deb http://http.us.debian.org/debian stable main contrib non-free

run the following on a root terminal

#apt-get update
#apt-get install python-gpib

Also install the documentation etc. //using synaptic package manager


->do not run apt-get update while synaptic package manager is open .. they both use the same base!

now .. the gpib drivers have hopefully been configured on your pc


and the development toools are in place

run gpib config

#gpib_config --minor 0

minor in my case is zero

editing gpib.conf to add your devices

#gedit /etc/gpib.conf

the file is pretty much self explanatory with comments everywhere

the basic changes I made in my case

my file is as follows  /etc/gpib.conf

/***********************************************************************
                 GPIB.CONF IEEE488 library config file
                             -------------------

   copyright            : (C) 2002 by Frank Mori Hess


                          (C) 1994 by C.Schroeter
   email                : fmhess@users.sourceforge.net
 ***************************************************************************/
/***************************************************************************
 *    
 *   Syntax:
 *
 *         interface { ... } starts new interface board section
 *         device {...} device configuration
 *
 ***************************************************************************/

/* 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 = "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 */

/* settings for boards that lack plug-n-play capability */


    base = 0    /* Base io ADDRESS                  */
    irq  = 0    /* Interrupt request level */
    dma  = 0    /* DMA channel (zero disables)      */

/* pci_bus and pci_slot can be used to distinguish two pci boards supported by the same driver */
/*    pci_bus = 0 */
/*    pci_slot = 7 */

    master = yes    /* interface board is system controller */


}

/* 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 */

    eos = 0xa    /* EOS Byte */


    set-reos = no /* Terminate read if EOS */
    set-bin = no /* Compare EOS 8-bit */
}

device {
    minor = 0
    name = "pcs"
    pad = 12
    sad = 0
}

---------------------------------------
i added two devices .. both conected to the same gpib usb dongle from National Instruments

the first being a Keithley 2001 multimeter


with primary address set to 16 in my case(primary addresses are set on the device itself)

and a Keithley 224 programmable current source with primary address set as 12

--------------------------------------

Running test programs in C language

open root terminal

# 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?

to ask for reading

'r' to read
read 100 bytes

total commands entered and results are as follows

:w
enter a string to send to your device: :FUNC 'res'
sending string: :FUNC 'res'

gpib status is:


ibsta = 0x2100  < END CMPL >
iberr= 0

ibcnt = 12
------------------------
:w
enter a string to send to your device: :DATA?
sending string: :DATA?

gpib status is:


ibsta = 0x2100  < END CMPL >
iberr= 0
ibcnt = 7
-----------------------

: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

to modify it and run it


#gedit ibtest.c
after editing and saving
#make
# ./ibtest

to run your own programs


go to
http://sourceforge.net/projects/linux-gpib/files/

download the file

Download Now! linux-gpib-3.2.14.tar.gz (1.2 MB)

using the terminal ,change the directory to where you downloaded it


e.g.
# cd /home/jithin/Desktop

untar the file

# tar zxf linux-gpib-3.2.14.tar.gz


# cd linux-gpib-3.2.14/

 #./configure
#make
#rm /lib/modules/2.6.26-1-686/gpib
#make install

to compile your own programs

#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

open http://localhost/ using your web browser ...

this opens a file index.html stored in a location defined in /etc/apache2/sites-available/default

the default location is /var/www/

to edit the location and set your own hosting directory

# gedit /etc/apache2/sites-available/default

edit the line DocumentRoot <location>


and replace it with your own hosting directory location

add the following lines to it

<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

within your specified directory

create a file mptest.py

from mod_python import apache

def handler(req):
          req.content_type = 'text/plain'
          req.write("Hello World!")
          return apache.OK
save it and restart apache

#apache2ctl restart

now, in your browser address bar, type


http://localhost/mptest.py

the output should be

Hello World!

if this happens , then the mod_python handler is working fine!


you can add more python programs of yours in the directory and put links in index.html

in "http://localhost/mptest.py" , localhost can be replaced by the IP address of the machine


and the page can be accessed from any other PC on the network
be sure to create a proxy exception for the IP in the browser window in case of a proxy server.

--------------------------------

handling gpib instruments using python

//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

so, run the following

# chmod a+x(r,w) /dev/gpib0


this sets necessary permissions

now , modify mptest.py to access your GPIB devices

example program..  again, valid for KEITHLEY multimeter

//read resistance.py
----------------------------------------------------

from mod_python import apache

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"

open the link on your PC to get the readings ..


to access from another PC on the network , replace localhost with the IP address of your own PC !!

Anda mungkin juga menyukai