Length of read in in python-gpib
Dietmar Schwertberger
dietmar at schwertberger.de
Sun Oct 16 12:11:48 EDT 2005
In article <4351a665$0$41142$14726298 at news.sunsite.dk>, Madhusudan Singh
<URL:mailto:spammers-go-here at 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
More information about the Python-list
mailing list