Commit graph

1405 commits

Author SHA1 Message Date
Ian Abbott
c2cf7c8018 demo/cmd: check subdevice exists and supports 'read' commands
Check the subdevice actually exists and that it claims to support 'read'
commands (SDF_CMD_READ subdevice flag set), bailing out early if not.
2016-11-08 14:15:35 +00:00
Ian Abbott
b7cb7f2331 demo/cmd: bail out if fail to prepare command
Check return value of prepare_cmd_lib() and exit if less than 0.

Also change prepare_cmd_lib() to write its error message to stderr
instead of stdout.
2016-11-08 13:48:56 +00:00
Ian Abbott
4329a08403 demo/cmd: default to the 'read' subdevice instead of subdevice 0
If the '-s' option has not been specified, default to using the current
'read' subdevice if there is one instead of defaulting to subdevice 0.
Fall back to using subdevice 0 if there is no 'read' subdevice.
2016-11-08 13:38:36 +00:00
Ian Abbott
9cf2bba2e0 README: Git repository migrated to github.com
Updated documented URL of git repository, and provided instructions for
updating the URL of previously cloned repositories.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
2016-09-19 15:30:14 +01:00
Ian Abbott
a2573fff8f doc/drivers.txt: Rebuilt from Comedi - capitalize ADLINK consistently
Use updated drivers.txt from the comedi.org Comedi package.  The
documentation for the ADLINK drivers has been updated to capitalize
ADLINK in a consistent manner.
2016-07-07 11:23:37 +01:00
Ian Abbott
f6c1318c6c doc/drivers.txt: Rebuilt from comedi
Rebuilt "doc/drivers.txt" using "make Documentation/comedi/drivers.txt"
in the Comedi package, which scans the driver sources for documentation.

Note: this is built from the comedi.org Comedi sources, not the Linux
"staging" Comedi sources.
2016-07-07 10:58:55 +01:00
Ian Abbott
c45f319171 comedi_test: deal with INSN_GTOD values more carefully
Try and avoid arithmetic overflow when converting the difference between
two INSN_GTOD timestamps to a signed number of microseconds.
2016-06-20 11:29:14 +01:00
Ian Abbott
a4dd004076 demo/insn: report start and end time as unsigned values
Report the seconds and microseconds values from the INSN_GTOD
instructions as unsigned values to postpone the Y2038 problem to a Y2106
problem.  Be a bit more careful with the conversion to a signed
difference.  We wouldn't normally expect time to go backwards, but it is
possible if the system time is set to to an older time between the
instructions.

Also, in the description of INSN_GTOD in the Comedilib manual,
explicitly mention that the seconds and microseconds values are
unsigned.
2016-06-20 11:09:55 +01:00
Ian Abbott
e0ee6039eb c++: Add a lot of missing wrapper functions to comedilib.hpp
Add missing C++ wrappers for most comedilib functions.  Also make some
of the existing wrappers 'const' where if that appears to have been
omitted.
2016-06-10 10:42:37 +01:00
Ian Abbott
70d6a02dd9 lib: dio: set internal error for incompatible subdevice type
comedi_dio_get_config(), comedi_dio_read(), comedi_dio_write(),
comedi_dio_bitfield2() (and comedi_dio_bitfield()) return -1 if the
subdevice type is unsuitable, but do not set an internal comedi error
code in that case.  Change them to do so.

Also, don't bother checking if instruction list ioctl is supported in
comedi_get_dio_config(), as it doesn't use it.
2016-06-09 15:04:28 +01:00
Ian Abbott
2fb6289b1c comedi.h: replace bare 'unsigned' with 'unsigned int' 2016-05-16 11:24:07 +01:00
Ian Abbott
7958fec6c5 doc: Makefile.am: rebuild manual when tutorial program source changes 2016-05-13 18:14:57 +01:00
Ian Abbott
6373588120 doc: include the full tut3.c program listing
Include the full tut3.c program listing in the document as it's not much
bigger than tut3_part.c and it's a pain maintaining both of them.
2016-05-13 17:55:39 +01:00
Ian Abbott
59c563fea6 demo: reformat the tutorial examples a bit 2016-05-13 17:45:15 +01:00
Ian Abbott
80d809282c demo: update demo programs to set read or write subdevice
Attempt to make the streaming command demos work if the specified
subdevice is not the default 'read' or 'write' subdevice (depending on
the direction of the command).

This uses the new comedi_set_read_subdevice() and
comedi_set_write_subdevice() functions.

Changing the read or write subdevice is currently supported only by the
Linux "in-tree" version of Comedi since kernel version 3.19.
2016-05-13 17:19:10 +01:00
Ian Abbott
7a8b838e66 demo: poll: fix polling of wrong subdevice
The call to comedi_poll() always sets the subdevice parameter to 0.  Set
it to the subdevice that the streaming command is using.
2016-05-13 16:42:14 +01:00
Ian Abbott
8c31fb88c1 lib: don't change read or write subdevice unnecessarily
Change comedi_set_read_subdevice() and comedi_set_write_subdevice() to
do nothing if the requested subdevice is already set as the current read
or write subdevice, respectively.

The functions now return success even if the Comedi drivers do not
support changes to the read or write subdevice as long as the specified
subdevice is the default one.
2016-05-13 16:18:02 +01:00
Ian Abbott
aff4937e03 Added some more buffer position functions for use with mmap
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.
2016-05-13 15:14:47 +01:00
Ian Abbott
fad46b9b16 doc: tweak some of the documentation for streaming acquisition functions 2016-05-13 14:30:19 +01:00
Ian Abbott
22caa42aee doc: command_funcref.txt: fix DocBook tag
Change '<em>' to '<emphasis>'.
2016-05-13 14:19:58 +01:00
Ian Abbott
67a364cf93 comedi_test: attempt to change read and write subdevice during test
When testing streaming input (or streaming output) command functionality
for a subdevice, attempt to make it the current 'read' (or 'write')
subdevice by calling the new 'comedi_set_read_subdevice()' (or
'comedi_set_write_subdevice()') function.

That is currently only supported by the Linux "in-tree" version of
Comedi, since kernel version 3.19.  If the attempt fails, and the
subdevice is not the current 'read' (or 'write') subdevice, the test
will report "not applicable" as before.
2016-05-13 11:48:31 +01:00
Ian Abbott
ae03f3932e swig/ruby: update bindings
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.
2016-05-12 19:35:40 +01:00
Ian Abbott
5762a1dd60 doc: corrected link content comedi_cleanup_calibration_file
'comedi_cleanup_calibrate_calibration_file' should be
'comedi_cleanup_calibration'.
2016-05-12 19:08:31 +01:00
Ian Abbott
43a3ae9a27 comedilib.h: Don't mark 'data' parameter of comedi_data_read_n for SWIG
The 'data' parameter (of type lsampl_t*) for
comedi_data_read_n(it,subd,chan,range,aref,data,n) is currently marked
as an OUTPUT parameter for SWIG, but we can only do that for single
objects, and this one points to an array of objects.
2016-05-12 18:52:35 +01:00
Ian Abbott
aec40a79aa doc: refer to device file descriptors rather than device files 2016-05-12 18:18:08 +01:00
Ian Abbott
66070c6af6 Add comedi_set_read_subdevice() and comedi_set_write_subdevice()
These functions allow the current read or write subdevice to be changed
to another subdevice that supports streaming input (for read), or
streaming output (for write) asynchronous commands.

They return 0 on success, in which case the comedi_get_read_subdevice()
or comedi_get_write_subdevice() functions will get the updated read or
write subdevice.

Changes are local to the "open file description" that was created by
comedi_open() (actually, by open()), and have no effect on other open
file descriptions created by other calls to comedi_open() (or open())
for the same underlying Comedi device node.

Changes to the read or write subdevice is not currently supported by the
comedi.org version of the Comedi drivers, but is supported by the Linux
"in-tree" Comedi drivers since kernel version 3.19.
2016-05-12 18:10:59 +01:00
Ian Abbott
6458b08e56 lib: remove some unnecessary setting of __comedi_errno
Since comedi_ioctl() calls libc_error() to set __comedi_errno to errno
(and possibly print an error message), there is no need for callers of
comedi_ioctl() to set __comedi_errno immediately afterwards.  But
comedi_command(), comedi_command_test(), and comedi_do_insnlist()
currently do that.  Remove the unneeded setting of __comedi_errno in
those functions.

Also, comedi_command() and comedi_command_test() check __comedi_errno
regardless of whether comedi_ioctl() returnis an error, and possibly
modify the error code to an internal comedi error.  Change them to only
do that if comedi_ioctl() returns an error, because __comedi_errno might
contain a stale value.
2016-05-12 16:12:43 +01:00
Ian Abbott
27509ba9c9 Add digital trigger configuration functions
Add wrapper functions for the INSN_CONFIG_DIGITAL_TRIG configuration
instruction.  These are comedi_digital_trigger_disable(),
comedi_digital_trigger_enable_edges(), and
comedi_digital_trigger_enable_levels().
2016-03-21 11:28:29 +00:00
Ian Abbott
c85d380b93 comedilib.h: fix a typo in a comment 2016-03-21 11:28:29 +00:00
Ian Abbott
ac2ce44520 Add channel-specific arm, disarm, and reset wrappers.
The comedi_arm(), comedi_disarm(), and comedi_reset() functions always
set the channel number in the corresponding configuration instructions
to 0, as they assume the channel number will be ignored by the driver.
Some drivers do in fact use the channel number in these configuration
instructions.  Add additional wrapper functions comedi_arm_channel(),
comedi_disarm_channel(), and comedi_reset_channel() to allow the channel
number to be specified.
2016-03-21 11:28:29 +00:00
Ian Abbott
2062d615ff Add comedi_disarm() and bump to 0.11.0
Add the comedi_disarm() function to send the INSN_CONFIG_DISARM
configuration instruction to a subdevice.

In configure.ac, bump the comedilib libtool version code to 11:0:11, so
the comedilib version becomes 0.11.0.  Also bump the comedilib manual
version to 0.11.0 in doc/comedilib.ent.
2016-03-21 11:28:29 +00:00
Ian Abbott
0378db7399 comedi.h: adjust header comment
Don't mention where the header gets installed.
2016-03-21 11:27:40 +00:00
Ian Abbott
8b01d77b80 comedi.h: Add note that the "aux data" config options are still used
The COMEDI_DEVCONF_AUX_DATA3_LENGTH, COMEDI_DEVCONF_AUX_DATA2_LENGTH,
COMEDI_DEVCONF_AUX_DATA1_LENGTH, COMEDI_DEVCONF_AUX_DATA0_LENGTH,
COMEDI_DEVCONF_AUX_DATA_HI, COMEDI_DEVCONF_AUX_DATA_LO, and
COMEDI_DEVCONF_AUX_DATA_LENGTH config option indices are still used by
the standalone COMEDI kernel modules built from comedi.org sources for
loading firmware in some driver modules, although they are no longer
used by the COMEDI kernel modules in the Linux kernel sources.  Adjust
the comment to reflect this.
2016-03-21 11:08:06 +00:00
Ian Abbott
ef4c4e2e08 Avoid using BIT(x) macro
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.
2016-03-21 10:35:16 +00:00
Spencer E. Olson
32cb61fe90 Reimplement 371dcc56e6f7(strip comedi_/COMEDI prefix)
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.
2016-03-19 22:54:37 -06:00
Spencer E. Olson
b9821b9d8c Sync removal of obsolete/useless items in comedi.h
This patch removes COMEDI_CB_* macros that are of no use to userspace at
any rate.  COMEDI_CB_* are no longer in comedi.h in the staging tree, but
rather in comedidev.h.

This patch also removes an old commented-out INSN_CONFIG_GET_OTHER_SRC, the
value of which was already taken long ago by
INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE.
2016-03-18 12:26:52 -06:00
Spencer E. Olson
5d36757aa6 Move old items of comedi.h into new "deprecated" section
This allows the body of comedi to maintain visual sync to that of the
staging tree.
2016-03-18 12:19:22 -06:00
Spencer E. Olson
5cb320d559 Use BIT(x) macro for better sync to staging comedi.h
This patch defines a copy of the kernel BIT(x) macro and syncs the use of
BIT(x) between the staging tree and comedilib versions of comedi.h
2016-03-18 12:09:04 -06:00
Spencer E. Olson
0bb9805c82 Inherit documentation from staging comedi.h
This partial sync of staging tree to the comedilib version of comedi.h
brings documentation and some mild formatting.  The documentation should be
beneficial to userspace and the sync helps to visually maintain future
syncing between kernel and userspace code.
2016-03-18 12:05:17 -06:00
Spencer E. Olson
823bf1e398 Teach SWIG to properly handle some unsigned consts for python
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.
2016-03-18 10:17:11 -06:00
Spencer E. Olson
9d4b7367eb change static inline NI_* to macros
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.
2016-03-18 10:12:37 -06:00
Ian Abbott
ba27bddca4 include/comedi.h: synced with comedi
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
2016-03-18 12:07:08 +00:00
Spencer E. Olson
3f19af6b53 Documents stop_arg!=0 when stop_src=TRIG_NONE
This patch documents the new interpretation of stop_arg when stop_src ==
TRIG_NONE.  In the new interpretation, if stop_src==TRIG_NONE, a user may
specify that a buffer of finite length (and less than or equal to the
maximum buffer size) be repeated indefinitely.

For now, only the NI MIO driver implements this new interpretation.  All
other drivers should continue to force stop_arg==0 when
stop_src==TRIG_NONE.  In this case, the old behavior is maintained.
2016-03-08 22:47:52 -07:00
Spencer E. Olson
ea09b60196 update supported hardware list to include NI PXI-6251 2016-03-08 22:42:34 -07:00
Ian Abbott
65063d785e demo/mmap: support integer wraparound and large sample size
Currently, the 'front' and 'back' variables are of type 'int' (signed
32-bit integers).  The loop will break when 'front < back', which will
happen when more than 'INT_MAX' bytes of data have been produced.
Redefine them as 'unsigned int' and also allow 'front < back' which will
happen when more than 'UINT_MAX' bytes of data have been produced.
Because the buffer size is not necessarily a power of 2, we can no
longer just use '(back + i) % size' to get the buffer position
corresponding to 'back + i', so introduce a new variable 'bufpos' to
keep track of the buffer position.

Also allow for subdevices that set the 'SDF_LSAMPL' flag to indicate
they use the large (32-bit, 'lsampl_t') sample type instead of the small
(16-bit, 'sampl_t') sample type.

Also, rename the buffer size variable 'size' to 'bufsize'.
2015-11-23 16:04:11 +00:00
Ian Abbott
49f298cf86 lib/range.c: deal with samples > maxdata when converting to phys
By default, comedi_to_phys() and comedi_sample_to_phys() return NAN (not
a number) if the raw sample value is 0 or maxdata.  Change it to convert
any raw sample values above maxdata to NAN.  Such raw samples shouldn't
occur, but this seems like a sensible thing to do.  (Note that the
conversion of out-of-range values to NAN behavior can be changed via the
comedi_set_global_oor_behavior() function.)
2015-08-24 17:33:11 +01:00
Ian Abbott
3e337824f4 lib/calib_yacc.y: fix segfault in comedi_parse_calibration_file()
Don't call fill_inverse_linear_polynomials(priv.parsed_file) if
priv.parsed_file is NULL as that would dereference the NULL pointer
leading to a segmentation fault.
2015-08-20 13:02:53 +01:00
Ian Abbott
abb45335e3 doc: Bump to version 0.10.3. 2015-06-08 11:53:50 +01:00
Ian Abbott
6065b188d1 configure.ac: Bump to 0.10.3
Bump the comedilib libtool version code to 10:3:10, so the comedilib
version becomes 0.10.3.
2015-06-08 11:52:07 +01:00
Éric Piel
da0fe745fc include: explicitly indicate values are unsigned when it could matter
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.
2015-06-08 11:21:11 +01:00