Re: python/comedi

bryan cole wrote:
> The current CVS version of the interface file does not generate wrappers
> which handle function-results passed by reference. When I wrote the
> file, I didn't think Comedilib passed anything by reference but I since
> found a couple of functions which do (e.g. comedi_data_read and
> comedi_data_read_delayed). To handle these I needed to copy most of the
> comedilib headers into the comedi.i file, strip out the unnecessary
> stuff and edit it to let SWIG know which pointer-arguments are 'output'.

Just to be clear, the current version in CVS (comedilib/swig/ruby) is 
not the original you provided (comedilib/python). Frank and I made 
several updates to it, including marking parameters as OUTPUT or INOUT 
as noted. I couldn't make the Ruby interfaces work without those 
changes, and I couldn't imagine how the Python interfaces would work 
without them.

I tried to make sure that the Python demo programs work with the updated 
interface file. As far as I know, they do.

I also did a few things to sweeten the Ruby interface a little. The same 
thing is applicable in principle to Python, although the mechanism will 
be different. (I don't know much Python.) The key is to note that SWIG 
puts comedilib into a module (Comedi) and also preserves the 'comedi_' 
prefix on every function. Neither prefix is necessary to disambiguate 
instance methods of classes in module Comedi.

For example: instead of saying

dev = Comedi::comedi_open('/dev/comedi0')
...
ret, cmd = Comedi::comedi_command_test(dev, cmd)

you can say

dev = Comedi::open('/dev/comedi0')
...
ret, cmd = dev.command_test(cmd)

I built a table of function names and classes and used that to generate 
wrappers, e.g.,

module Comedi
   class SWIG::TYPE_p_comedi_t
     def command_test(*args)
       comedi_command_test(self, *args)
      end
   end
end

I also added some stuff to raise Ruby exceptions. The general idea is to 
make the API idiomatic in Ruby, as the original is in C. (The C-like API 
is still there in Ruby.)

If anybody wants to steal this for Python, you're welcome to it. The 
Ruby wrapper definitions could probably be brute-force translated into 
their Python equivalents by someone whose Python is better than mine.

Steve

Received on 2004-03-22Z21:06:28