473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Length of read in in python-gpib

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
2 4512
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Noam Raphael | last post by:
Hello, Many times I find myself asking for a slice of a specific length, and writing something like l. This happens both in interactive use and when writing Python programs, where I have to write...
5
by: wolfgang haefelinger | last post by:
Greetings, I'm trying to read (japanese) chars from a file. While doing so I encounter that a char with length 2 is returned. Is this to be expected or is there something wrong? Basically...
2
by: Greg Lindstrom | last post by:
Hello- I'm creating fixed-length record layouts for various record translations I need to perform. I have been using a home-grown object, "FixedLengthRecord" for about 4 years now and am very...
2
by: Jeff L. | last post by:
Maybe I'm missing the obvious solution because I've been looking at this problem for so long, so I figured I'd throw it out and see if anyone can come up with some ideas. :) I'm writing a...
2
by: Al Knowles | last post by:
I am having a lot of trouble understanding the last parameter of the XmlTextReader's ReadBase64 method,length. In all the examples I have been able to find on the web, the developer seems to...
14
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I...
4
by: dale zhang | last post by:
Hi, I am trying to save an image to MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp For save button, I converted his VB to the following C#....
11
by: John Salerno | last post by:
Given: numbers = can someone explain to me why numbers results in ? I thought the first index, whether going forward or backward, was inclusive. And there is no index of 10 in this...
0
by: Edwin.Madari | last post by:
here is a working code snippet to read from MySQL db. python tutorial has examples of reading from files. put them together to do your task. ===================================================...
16
by: sotirac | last post by:
Wondering if there is a better way to generate string of numbers with a length of 5 which also can have a 0 in the front of the number. <pre> random_number = random.sample(, 5) # choose 5...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.