Length of read in in python-gpib

Discussion in 'Python' started by Madhusudan Singh, Oct 16, 2005.

  1. 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)
     
    Madhusudan Singh, Oct 16, 2005
    #1
    1. Advertising

  2. 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.
     
    Madhusudan Singh, Oct 16, 2005
    #2
    1. Advertising

  3. In article <4351a665$0$41142$>, Madhusudan Singh
    <URL:mailto:> 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
     
    Dietmar Schwertberger, Oct 16, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chaser
    Replies:
    7
    Views:
    400
    Michael Sweeney
    Nov 9, 2004
  2. whoopsi

    help w/ simple GPIB prog.

    whoopsi, Oct 4, 2005, in forum: Python
    Replies:
    1
    Views:
    624
    Torsten Bronger
    Oct 4, 2005
  3. whoopsi

    help w/ simple GPIB prog.

    whoopsi, Oct 4, 2005, in forum: Python
    Replies:
    1
    Views:
    472
    Dietmar Schwertberger
    Oct 4, 2005
  4. Torsten Bronger
    Replies:
    0
    Views:
    526
    Torsten Bronger
    Jan 24, 2006
  5. Torsten Bronger
    Replies:
    0
    Views:
    546
    Torsten Bronger
    Nov 22, 2006
Loading...

Share This Page