The lines:
%rename("%(strip:[COMEDI_])s", regextarget=1) "COMEDI_.*";
%rename("%(strip:[comedi_])s", regextarget=1) "comedi_.*";
caused errors on import due to _comedi function names not matching at
import time. Stripping names is now completely done in the globals()
modification at the end, which works properly.
to indicate if the old names should be stripped or not. This makes the
intent very clear in the generated comedi.py file.
[Reformatted commit message -- Ian Abbott]
Fixed Python3 incompatibility created by trying to modify module
globals() in iterator. Also simplified breaking backwards compatibility
switch as #define SWIGPYTHONONLYSHORT
[Reformatted commit message -- Ian Abbott]
Added comedi_get_buffer_read_offset(), comedi_get_buffer_write_offset(),
comedi_get_buffer_read_count(), and comedi_get_buffer_write_count().
comedi_get_buffer_read_offset() is the same as
comedi_get_buffer_offset(), which has now been documented as deprecated,
but is currently still declared in "comedilib.h" by default. It gets
the read position within the buffer as an offset from the start of the
buffer (modulo the buffer size).
comedi_get_buffer_write_offset() gets the write position within the
buffer as an offset from the start of the buffer (modulo the buffer
size).
comedi_get_buffer_read_count() gets the number of bytes read from the
buffer, modulo UINT_MAX+1.
comedi_get_buffer_write_count() gets the number of bytes written to the
buffer, modulo UINT_MAX+1.
Add methods for several Comedilib functions that are currently absent
from the Ruby bindings.
Rename the comedi_to_physical, comedi_from_physical, and
cleanup_calibration_file methods to to_physical, from_physical, and
cleanup_calibration, either for consistency (comedi_to_physical and
comedi_from_physical) or because they are wrong
(cleanup_cleanup_calibration_file).
TODO: Add a binding for comedi_get_clock_source() as well, but I'm not
sure how to handle multiple output parameters.
The BIT(x) macro is used by some internal kernel headers and is not
used in user API kernel headers. It was used incorrectly in the
"staging" kernel version of "comedi.h" in the "linux-next" tree for a
brief period.
Replace the use of BIT(x) with explicit masks. Handle CR_INVERT
specially in SWIG to avoid it appearing as a negative integer.
_CR_FLAGS_MASK was defined twice, identically, in SWIG, so remove one of
the definitions.
This patch reimplements 371dcc56e6 where the comedi_/COMEDI_ prefix was
removed. Just like that patch, this patch also allows for all old names
to resolve properly. Differently than that patch, this patch simply adds
new items in the modules dictionary with the comedi_/COMEDI_ prefix
removed. Benefits of this approach:
1) Do not have to create a fake module.
2) Tab completion works well in ipython/python since the module is left
intact.
3) Adding new items without the comedi_/COMEDI_ prefix happens only once at
module load time, instead of every time an item is requested from the
module.
This revisits the change made in da0fe745fc:
1) Changes c-macro constants back to their original definition (without
explicit typing them as unsigned) so-as to more exactly compare
the comedilib version of comedi.h with that of the kernel module.
2) Removes the duplicate definition of NI_GPCT_INVERT_CLOCK_SRC_BIT in
comedi.i.
3) Instead of redefining the macros to fix the mishandling of signedness
by SWIG for python, teach SWIG to treat these as unsigned ints.
This is a partial sync of the staging tree to comedilib with these
benefits:
1. This is first in a series of patches to sync comedilib to the kernel
modules in the staging development tree. The point of this series of
patches is to make the syncing of the userspace and kernel comedi.h
files be visually more easily done.
2. This patch also teaches SWIG out to properly wrap these macros and
provide them to the user.
3. The redef of static inline NI_* functions as macro functions eases
alternative use of comedi.h as an import source for a new ctypes-based
python interface for comedilib.
In C, mixing up between int and unsigned int doesn't matter too much for constants
because in memory they end up the same.
However, in Python, they appear differently.
Swig assumes (wrongly?) by default that the constants are signed, intead of being unsigned.
For every value equal or greater that 2**31, it matters.
For instance CR_INVERT should be 2147483648, but it is -2147483648 in python.
By marking the values explicitly unsigned, swig generates the right values.
That's excepted for enum, which swig just consider int. So for the only constant in that
case, we manually override it in swig.
python always use the namespace of the library so it was redundant.
so what used to be written comedi.comedi_open() can be written comedi.open().
The main trick is to add a special python code that allows for the old names to still be compatible.
That avoids to break every single python program previously written.
I also added 2010 for:
commit 3fe8e6baac
Author: Ian Abbott <abbotti@mev.co.uk>
Date: Mon Dec 20 14:50:21 2010 +0000
Add sampl_t and lsampl_t array_class()es to comedi.i.
...
Patch from W. Trevor King.
The old method only worked out of the box if you were running Python
2.1 on a 586. I imagine that is too small a slice of current users to
be worth hard coding ;).
This makes it possible to populate `comedi_insnslist_struct` for use
with `comedi_do_insnlist`.
I also removed my earlier re-typedefs of `sampl_array` and
`lsampl_array`. I didn't understand the reason for the underlying
`TypeError` when I added them. The proper way to avoid that error is
to use the `.cast()` and `.frompointer()` methods. See
`demo/python/insn.py` (coming soon) for details.
line-lengths for 80-character wide terminals. Most of the updated text
supplied by W. Trevor King. Ian Abbott added a note that it only applies
when building the wrappers separately from Comedilib without 'make'.
Add "comedi_python.i" swig interface file which merely %includes the
"comedi.i" in the parent directory. Fix paths in "setup.py" and set it up
to run swig directly (using "comedi_python.i" as the source). Change
"_comedi.py" to "comedi.py" (but keep the underscore prefix on the .so
and .la files).
Based on a patch by W. Trevor King.
The SWIG interface file (swig/comedi.i) is out of date with respect to comedi.h
and comedilib.h. I've attempted to make it current by applying most of the
changes since 1.22 (both headers).
My ability to test is limited. The swig/ruby/demo/cmd application runs
successfully using the comedi_test device. The python extension library
compiles, but that's as far as I've taken it.
'setup.rb config' calls 'extconf.rb' in the ext directory to build the extension
Makefile. 'extconf.rb' looks for C source files in the directory when it runs,
so SWIG needs to run before 'setup.rb config'. The attached patch makes the
output of SWIG a prerequisite for ext/Makefile.
If configure attempts to build the Ruby extension on a system without a previous
installation of comedilib, compilation fails because gcc can't find comedilib.h.
The attached patch adds the distribution include directory to the gcc search
path when compiling the extension.
The attached patch updates files in comedilib/swig/ruby. lib/comedi.rb is
updated to raise Ruby exceptions as indicated by the comedilib API
documentation. README and demo/cmd are updated accordingly.