By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,928 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,928 IT Pros & Developers. It's quick & easy.

Length of read in in python-gpib

P: n/a
python-gpib provides Gpib.py (see end of post) for Linux.

I am trying to use the method called read. I usually use it without
arguments (the default length being 512). However, I am trying to read in a
string with some 16,000 comma separated floating point numbers.

So, I have to pass a length parameter much much larger than 512. As is
stands, the default read takes in only about 35-40 numbers, so I need about
512/35*16000 ~= 230,000. Not being sure if I could make python read in
something that big, I started small - with 1024. This produces an list of
numbers that has a malformed first number (I get 88309e-9 instead of
something like 6.788309e-9.).

Could this be a bug ?

Second, does the length need to be a power of two for some reason ?

python-gpib is an excellent library, but it suffers from an utter lack of
documentation.

------------------------ Gpib.py -----------------------------
import gpib

RQS = (1<<11)
SRQ = (1<<12)
TIMO = (1<<14)
class Gpib:
def __init__(self,name='gpib0'):
self.id = gpib.find(name)
def write(self,str):
gpib.write(self.id, str)

def writebin(self,str,len):
gpib.writebin(self.id,str,len)
def read(self,len=512):
self.res = gpib.read(self.id,len)
return self.res

def readbin(self,len=512):
self.res = gpib.readbin(self.id,len)
return self.res

def clear(self):
gpib.clear(self.id)

def wait(self,mask):
gpib.wait(self.id,mask)

def rsp(self):
self.spb = gpib.rsp(self.id)
return self.spb

def trigger(self):
gpib.trg(self.id)

def ren(self,val):
gpib.ren(self.id,val)

def ibsta(self):
self.res = gpib.ibsta()
return self.res

def ibcnt(self):
self.res = gpib.ibcnt()
return self.res

def tmo(self,value):
return gpib.tmo(self.id,value)
Oct 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Further, if I use 131072 (2^17) as the length, I get an error :

Traceback (most recent call last):
File "takedata.py", line 74, in ?
x=sr.querytrca(srs,1,0,4000,131072)
File "/home/labmonkey/code/oledpmt/sr830.py", line 62, in querytrca
trca=sr.read(n)
File "/usr/lib/python2.3/site-packages/Gpib.py", line 22, in read
self.res = gpib.read(self.id,len)
gpib.error: Read Error: ibrd() failed

Following this, an attempt to run the script again chokes at the first
(harmless - just setting some instrument parameter - ibwrt() fails) gpib
command and then locks the bus, freezing the whole system unless I reboot
the system. This has happened twice.

I am using the Agilent82357a USB to GPIB convertor. Have used it for
numerous purposes with the same setup, but the library seems to be choking
on this new application. The instrument I am trying to use is an SR830
lockin amplifier.
Oct 16 '05 #2

P: n/a
In article <43***********************@news.sunsite.dk>, Madhusudan Singh
<URL:mailto:sp**************@spam.invalid> wrote:
python-gpib provides Gpib.py (see end of post) for Linux.

I am trying to use the method called read. I usually use it without
arguments (the default length being 512). However, I am trying to read in a
string with some 16,000 comma separated floating point numbers.


I've never used python-gpib, but I'm using National Instrument GPIB
cards with a wrapper that loads the driver DLL using ctypes.
Usually for such long data you have to perform multiple read operations and
check the card/bus status whether the read operation is finished
(Code "END" - "END or EOS detected").
So with the National Instrument drivers I'm checking whether ibsta is
something like 0x2000, i.e. 1<<13.

The following code is a snippet from my sources.
Hope this helps. From your post I can see that python-gpib also provides
an ibsta method. I'd expect that END is also 1<<13.

Regards,

Dietmar

import ctypes

gpib = ctypes.windll.LoadLibrary("gpib-32")

# read buffer
_bufsize = 1024
_buffer = ctypes.c_buffer(_bufsize)

_readstatus = 0x2000
_errorstatus = 0x8000

def get_ibcntl():
return ctypes.c_int.in_dll(gpib, "user_ibcntl").value

def ibrd(handle):
ret = []
ibsta=0
global _buffer

while not (ibsta & _readstatus):
ibsta = gpib.ibrd(handle, _buffer, _bufsize)
new = _buffer.raw[:get_ibcntl()]
ret.append( new )
if ibsta & _errorstatus:
_raise(GPIBIOError,
"ibrd(handle=%d): Could not read data."%handle, ibsta )
ret = "".join(ret)
if '\012' in ret:
ret = ret[0:string.find(ret, '\012')]
if '\015' in ret:
ret = ret[0:string.find(ret, '\015')]
return ret

Oct 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.