- From: JUSTIN ABRAHAM <abrjus002_at_uct.ac.za>
- Date: Mon, 17 Sep 2007 12:49:48 +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...??
##################################################
#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??
>>> Heinrich du Toit <heinrichdt_at_tlabs.ac.za> 09/17/07 9:05 AM >>>
Send me what you have so far - like the 2 seperate programs.
Comedi and DAQmxBase code are just about 100% different.
So there is really no point in giving you DAQmxBase code if you want to
work with comedi.
DAQmxBase is a pain - I had to install SuSE just for that - and SuSE is
even worse.
I haven't done simultaneous read/write in comedi yet. Will do that some
time in the future - can't say when - but it needs doing.
The way I understand it:
There is atleast 2 sub devices - 1 for analog out and 1 for analog in.
So you will need 2 comedi_cmd_struct's filled.
One for the analog output and 1 for the analog input.
Then I suggest running comedi_command_test with on both of these cmd
struct's. - just to make sure.
Then you need to start both commands with comedi_command.
Now here is where I'm not sure how things are suppose to work.
Either you can just directly read/write to the comedi dev (using
write(comedi_fileno(dev), ect ...
and read(comedi_fileno(dev), ect ...
But I'm not sure.
It should work If I understand this correctly:
http://www.comedi.org/doc/r6162.html
use comedi_find_subdevice_by_type to get the 2 different subdevice
numbers for the 2 different commands your running.
ok that's about as usefull as I can try and be
Received on 2007-09-17Z09:49:48