clade/PyDAQmx — pull request #6 by quigybo (2013-10-15 22:55:58+00:00)
Title: Miscellaneous bug fixes and improvements

Here are some miscellaneous fixes for things that I have noticed while looking
through the PyDAQmx code. I hope that each commit is self-explanatory enough,
otherwise please let me know and I will give more details where necessary.

ffba392 fixes a bug where a `TypeError` is raised in the `__repr__` of closed
tasks. This problem arises with newer versions of the NI library (starting with
2010) as the task handle is stored as a `c_void_p`, however `c_void_p(0).value`
returns `None` and not `0`.

f9da57b adds slightly stricter type checking on `numpy` data arrays, in
particular enforcing `C_CONTIGUOUS` and `WRITEABLE`.

I was also curious as to why you don't set the `restype` of the functions in
the library? The default `restype` for `ctypes` function pointers is `c_int`,
and `NIDAQmx.h` typedefs `int32` to `long`. Would it be safer to explicitly
parse the header and set the `restype` for systems where `sizeof(int) !=
sizeof(long)`?

59d3776 adds an example of a way to synchronise the asynchronously-called
`EveryNSamplesEventCallback` with a main thread using some `threading`
primitives (`Lock` and `Event`). Do you think this is also worth adding to the
online documentation? Or at least adding a link to it? (It may have to be added
separately after both this and #5 have been merged.) I was also curious, do you
know of a better way of solving this type of problem that I haven't thought of?
Note that this file uses Unix-style line termination, similar to the files in
`PyDAQmx` but unlike the files in `PyDAQmx/examples` (DOS-style). I wasn't sure
if I should adhere to the style of the code itself or the existing examples, so
please let me know if you would like this changed. Is there any particular
reason for the differing file types in the source repository?

In 54c53f8 and 9d90a73 I cleaned up the regular expression matching a little,
but ideally the header file should only be loaded once instead of twice
(currently it is loaded once in `DAQmxFunctions` and then again in
`DAQmxConstants`), especially considering its size (the 2012 version I have
here has 8252 lines).

The remaining commits should be straightforward enough and should not warrant
further explanation.

If any of the individual commits or questions above warrant an extended
discussion please let me know and I can open a separate issue to hold the
discussion in.