Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Length of read in in python-gpib

Reply
Thread Tools

Length of read in in python-gpib

 
 
Madhusudan Singh
Guest
Posts: n/a
 
      10-16-2005
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)
 
Reply With Quote
 
 
 
 
Madhusudan Singh
Guest
Posts: n/a
 
      10-16-2005
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.
 
Reply With Quote
 
 
 
 
Dietmar Schwertberger
Guest
Posts: n/a
 
      10-16-2005
In article <4351a665$0$41142$(E-Mail Removed)>, Madhusudan Singh
<URL:(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Smart or stupid? Tying textbox length to database column length Dan Manes ASP .Net 1 04-23-2006 10:57 PM
911...Need Help! : Length cannot be less than zero. Parameter name : length manmit.walia@gmail.com ASP .Net 2 01-10-2006 03:29 PM
left(string, length) or right(string, length)? Sam ASP .Net 3 02-17-2005 12:01 PM
System.ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length =?Utf-8?B?SG96aQ==?= ASP .Net 1 06-01-2004 11:06 PM
How to get length of string? length() problems Mitchua Perl 5 07-17-2003 12:08 AM



Advertisments