[prev in list] [next in list] [prev in thread] [next in thread]
List: comedi
Subject: RE: help: python wrapper for comedilib
From: "JUSTIN ABRAHAM" <abrjus002 () uct ! ac ! za>
Date: 2007-09-19 9:40:51
Message-ID: 46F10AC4020000850003FB85 () SRVNOVNGW002 ! uct ! ac ! za
[Download RAW message or body]
Dear Paul,
Thanks a lot for your reply and the code snippet. I'd really appreciate it if you \
could forward me the full 'cmd.py'. I have modified the test_'comedi.py' script and \
populated the cmd struct. It passes all the 'comedi_command_test(dev,cmd)' tests but \
it fails when i try execute the command ('c.comedi_command(dev,cmd)'). Your code will \
be very helpful.
Justin
> > > Paul Finnigan <paul@pfinnigan.plus.Com> 09/18/07 8:33 PM >>>
Justin
I am reading your posting on my mobile phone not ideal for looking at code. I hope \
this is readable.
You could be correct about your command construction. I had similar problems when I \
first looked at comedilib, which I use exclusivley with python as I cannot write C \
very well (it's about as good as my English).
When I first started out I did hit a few problems with Luc Lefebvre's scripts. It was \
difficult to come to terms with much of the documentation. While they emulate the \
functionality they are not copies of the C programs. I am attempting to rewrite all \
the demo programs in python, using the C program as the basis.
I have cmd.py rewritten and a few others, but the documentation and comments need \
sorting out. I even have a common.py under development to make sure they are as \
similar as is possible! In cmd.c a routine called prepare_cmd_lib is used to populate \
the command structure. I have emulated this under python using:
def prepare_cmd_lib(dev,subdevice,cmd):
"""
This prepares a command in a pretty generic way. We ask the
library to create a stock command that supports periodic
sampling of data, then modify the parts we want
"""
# This comedilib function will get us a generic timed
# command for a particular board. If it returns -1,
# that's bad.
ret = c.comedi_get_cmd_generic_timed(dev,subdevice,cmd,int(1e9/com.freq));
if ret<0:
print "comedi_get_cmd_generic_timed failed"
return ret
# Modify parts of the command
cmd.chanlist=chanl
cmd.chanlist_len= com.n_chan
cmd.scan_end_arg=com.n_chan
if cmd.stop_src==c.TRIG_COUNT:
cmd.stop_arg=com.n_scan
return 0
# The com.freq comes from my common module
# and is the Frequency (the default is 1000).
# cmd in the arguments is just the cmd structure you created
# using comedi_cmd_struct. If you want the whole of my cmd.py
# code then just ask. Everyone else will have to wait until I
# have had time to review my documentation.
-----Original Message-----
From: "JUSTIN ABRAHAM" <abrjus002@uct.ac.za>
To: comedi@comedi.org
Sent: 17/09/07 12:59
Subject: help: python wrapper for comedilib
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@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??
_______________________________________________
comedi mailing list
comedi@comedi.org
https://mail.comedi.org/cgi-bin/mailman/listinfo/comedi
--
This email has been verified as Virus free
Virus Protection and more available at http://www.plus.net
_______________________________________________
comedi mailing list
comedi@comedi.org
https://mail.comedi.org/cgi-bin/mailman/listinfo/comedi
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic