- From: JUSTIN ABRAHAM <abrjus002_at_uct.ac.za>
- Date: Mon, 17 Sep 2007 13:59:13 +0200
i'm programming using python with the python wrapper for comedilib. i've modified the test script that comes with the python wrapper. but it doesn't seem to be reading anything in...?? i've run some of the demo c-code provided with the card and its working fine. this script for some reason is not reading anything in...
##################################################
#A test-application to demonstrate using the Comedilib API
# and streaming acquisition in particular, from Python.
#This script is completely untested!
# author bryan.cole_at_teraview.co.uk
#set the paths so python can find the comedi module
import sys, os, string
import comedi as c
#open a comedi device
dev=c.comedi_open('/dev/comedi0')
if not dev: raise "Error openning Comedi device"
#get a file-descriptor for use later
fd = c.comedi_fileno(dev)
BUFSZ = 10000
nscans=1000 #specify total number of scans
#three lists containing the chans, gains and referencing
#the lists must all have the same length
chans=[0]
gains=[1]
aref =[c.AREF_GROUND]
nchans = len(chans) #number of channels
#wrappers include a "chanlist" object (just an Unsigned Int array) for holding the chanlist information
mylist = c.chanlist(nchans) #create a chanlist of length nchans
#now pack the channel, gain and reference information into the chanlist object
#N.B. the CR_PACK and other comedi macros are now python functions
for index in range(nchans):
mylist[index]=c.cr_pack(chans[index], gains[index], aref[index])
#construct a comedi command manually
cmd = c.comedi_cmd_struct()
cmd.subdev = 0
cmd.flags = 0
cmd.start_src = c.TRIG_NOW
cmd.start_arg = 0
cmd.scan_begin_src = c.TRIG_FOLLOW
cmd.scan_begin_arg = 0
cmd.convert_src = c.TRIG_TIMER
cmd.convert_arg = 1
cmd.scan_end_src = c.TRIG_COUNT
cmd.scan_end_arg = nchans
cmd.stop_src = c.TRIG_COUNT
cmd.stop_arg = nscans
cmd.chanlist = mylist
cmd.chanlist_len = nchans
#test our comedi command a few times.
ret = c.comedi_command_test(dev,cmd)
print "first cmd test returns ", ret
ret = c.comedi_command_test(dev,cmd)
print "second test returns ", ret
ret = c.comedi_command_test(dev,cmd)
if not ret: raise "Error testing comedi command"
#execute the command!
ret = c.comedi_command(dev,cmd)
if not ret: raise "Error testing comedi command"
#I think this will work but it's completely untested!
datalist=[]
data = os.read(fd,BUFSZ)
print len(data)
##################################################
the final 'print len(data)' outputs a 0, which means it hasn't read in anything and i don't know why??? maybe one of my parameters of cmd is wrong?? any ideas??
Received on 2007-09-17Z10:59:13