FAQ
Hi Ken!

In article <3AA46593.753BAE1 at newfocus.com>, Ken Koller
wrote:
Has anyone written a python interface to some of the National
Instruments libraries? I'm in the process of using Python to connect to
some instrumentation and I'm writing the C code to interface to their
GPIB API. Was hoping someone else had done it :)
Instead of using C you could just call the DLL using windll/calldll.


Example(s):
(not necessarily functional)

= NI_GPIB =================================================================
[snip]

from GPIB import *

import windll, calldll
gpib = windll.module("gpib-32")

def ibdev(BdIndx=0, address=(0,0), more=None):
'''ibdev(BdIndx=0, address=(0, 0), more=(11,1,0)):
Open and initialize a device descriptor (handle) for
use with subsequent calls for e.g. ibwrt and ibrd.
BdIndx Index of the access interface for the device
address The (primary, secondary) GPIB address of the device
more (The I/O timeout value, EOI mode of the device, EOS character and modes)
Returns the device descriptor or raises GPIBError.
'''
if more==None:
more=(11,1,0)
handle = gpib.ibdev( BdIndx, address[0], address[1], more[0], more[1], more[2])
if handle > 0:
return handle
_raise( GPIBIOError, "ibdev(BdIndx=%d, address=%s, more=%s): Could not get handle."%(BdIndx, str(address), str(more)) )

get_handle=ibdev

def ibwrt(handle, s):
'''ibwrt(handle, s):
Write data to a device from a user buffer.
handle: Interface or device descriptor
s: bytes to write
Returns None or raises GPIBIOError (or GPIBTimeoutError).
'''
wrbuffer = windll.cstring(s,len(s))
ibsta = gpib.ibwrt(handle,wrbuffer.address(),len(wrbuffer))
if ibsta <> _iocompletedstatus:
_raise(GPIBIOError, "ibwrt(handle=%d, s='%s'): Could not send string."%(handle, s), ibsta )

write = ibwrt


[snip]

boardID = 0
deviceaddress = (9,0)

# low level:
handle = ibdev(boardID, l)
ibwrt(handle, "*IDN?")

# higher level
bus = NI_GPIBInterface(boardID)
device = GPIBDevice(bus, address)
device.write("*IDN")

# highest level
multimeter1 = HP34970A(bus, address)
voltage = multimeter1.measure(range="10VAC", channel=5)

=========================================================================


I'm still working on the highest level classes for multimeters, sources,
source-monitor-units, relais scanners, ...


You may also try a search at google/deja for a posting by Sam Schulenburg:
# Forum: comp.lang.python
# Thread: Python and National Instruments
# Subject: Re: Python and National Instruments
# Date: 03/15/2000
# Author: Sam Schulenburg <samschul at pacbell.net>



Regards,

Dietmar

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 5 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedMar 6, '01 at 4:20a
activeMar 8, '01 at 2:20a
posts5
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase