473,588 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,n ame='gpib0'):
self.id = gpib.find(name)
def write(self,str) :
gpib.write(self .id, str)

def writebin(self,s tr,len):
gpib.writebin(s elf.id,str,len)
def read(self,len=5 12):
self.res = gpib.read(self. id,len)
return self.res

def readbin(self,le n=512):
self.res = gpib.readbin(se lf.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.i d)
return self.spb

def trigger(self):
gpib.trg(self.i d)

def ren(self,val):
gpib.ren(self.i d,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.i d,value)
Oct 16 '05 #1
2 4531
Further, if I use 131072 (2^17) as the length, I get an error :

Traceback (most recent call last):
File "takedata.p y", line 74, in ?
x=sr.querytrca( srs,1,0,4000,13 1072)
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************ ***********@new s.sunsite.dk>, Madhusudan Singh
<URL:mailto:sp* *************@s pam.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.L oadLibrary("gpi b-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(handl e, _buffer, _bufsize)
new = _buffer.raw[:get_ibcntl()]
ret.append( new )
if ibsta & _errorstatus:
_raise(GPIBIOEr ror,
"ibrd(handle=%d ): Could not read data."%handle, ibsta )
ret = "".join(ret )
if '\012' in ret:
ret = ret[0:string.find(r et, '\012')]
if '\015' in ret:
ret = ret[0:string.find(r et, '\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
1700
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 an expression twice (or use a temporary variable). Wouldn't it be nice if the Python grammar had supported this frequent use? My idea is that the expression above might be expressed as l.
5
2073
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 it's this what I'm doing: import codecs f = codecs.open("ident.in",'rb','Shift-JIS') ## japanses codecs installed
2
5248
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 happy with it. Almost. The burr under my saddle occurs when I serialize the record. Currently, I create an empty text field and for each record in my database (all record layouts, data types, lengths, defaults, etc. are held in an SQL server) I...
2
1986
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 server application using VB.NET that will be communicating with a device...the format that it uses can't be changed. The format is something like this: Device: <length><message> Server: <ack> (two null bytes, or "zero length")
2
3472
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 already know that value and hard codes it. I am attempting to pass a decoded base64 xmlstring from a vb6 application to a web service. The uploaded file is 336 bytes, but if my code works at all, it gets
14
5822
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 want to store data like a database: ---------------------------------- Custumer:
4
2385
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#. But the compiler complains: C:\Inetpub\wwwroot\passwordProtectCSharp\adminUserFile.aspx.cs(333): Cannot
11
1329
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 list, so what is it
0
179
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. =================================================== import MySQLdb con = MySQLdb.connect(host='127.0.0.1', port=4321, user='joe', passwd='shmoe', db='tst') cursor = con.cursor() sql = 'select * from YOUR_TABLE'
16
5186
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 elements code = 'this is a string' + str(random_number) + str(random_number) + str(random_number) + str(random_number) + str(random_number)
0
7860
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3883
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2371
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.