1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
4 <!ENTITY % comedilib_entities SYSTEM "comedilib.ent">
8 <section id="comedireference" xmlns:xi="http://www.w3.org/2001/XInclude">
13 <section id="comedi-comedilib-h">
15 Headerfiles: <filename>comedi.h</filename> and <filename>comedilib.h</filename>
19 All <link linkend="writingprograms">application programs</link> must
20 include the header file <filename>comedilib.h</filename>. (This file
21 itself includes <filename>comedi.h</filename>.) They contain the full
22 interface of &comedi;: defines, function prototypes, data structures.
25 The following Sections give more details.
30 <section id="constantsmacros">
35 <section id="ref-macro-CR-PACK">
41 <function>CR_PACK<parameter>chan</parameter><parameter>rng</parameter>
42 <parameter>aref</parameter></function> is used to initialize the elements of the
43 <parameter>chanlist</parameter> array in the
44 <type><link linkend="ref-type-comedi-cmd">comedi_cmd</link></type> data structure,
45 and the <parameter>chanspec</parameter> member of the
46 <type><link linkend="ref-type-comedi-insn">comedi_insn</link></type> structure.
50 #define CR_PACK(chan,rng,aref) ( (((aref)&0x3)<<24) | (((rng)&0xff)<<16) | (chan) )
54 The <parameter>chan</parameter> argument is the channel you wish to
55 use, with the channel numbering starting at zero.
59 The range <parameter>rng</parameter> is an index, starting at zero,
60 whose meaning is device dependent. The
61 <function><link linkend="func-ref-comedi-get-n-ranges">comedi_get_n_ranges</link></function>
63 <function><link linkend="func-ref-comedi-get-range">comedi_get_range</link></function>
64 functions are useful in discovering information about the available
69 The <parameter>aref</parameter> argument indicates what reference you
70 want the device to use. It can be any of the following:
73 <term><constant>AREF_GROUND</constant> <anchor id="aref-ground"/> </term>
76 is for inputs/outputs referenced to ground.
81 <term><constant>AREF_COMMON</constant> <anchor id="aref-common"/> </term>
84 is for a <quote>common</quote> reference (the low inputs of all the
85 channels are tied together, but are isolated from ground).
90 <term><constant>AREF_DIFF</constant> <anchor id="aref-diff"/> </term>
93 is for differential inputs/outputs.
98 <term><constant>AREF_OTHER</constant> <anchor id="aref-other"/> </term>
101 is for any reference that does not fit into the above categories.
106 Particular drivers may or may not use the AREF flags. If they are
107 not supported, they are silently ignored.
111 <section id="ref-macro-RANGE-LENGTH">
113 RANGE_LENGTH (deprecated)
117 Rangetype values are library-internal tokens that represent an
118 array of range information structures. These numbers are primarily
119 used for communication between the kernel and library.
123 The <function>RANGE_LENGTH<parameter>rangetype</parameter></function>
124 macro returns the length of the array that is
125 specified by the <parameter>rangetype</parameter> token.
129 The <function>RANGE_LENGTH</function> macro is deprecated, and should not be used in
130 new applications. It is scheduled to be removed from the header
131 file at version 1.0. Binary compatibility may be broken for version
136 <section id="ref-enum-comedi-conversion-direction">
138 enum comedi_conversion_direction
143 enum comedi_conversion_direction
151 A <type>comedi_conversion_direction</type> is used to choose between converting data
152 from Comedi's integer sample values to a physical value
153 (<constant>COMEDI_TO_PHYSICAL</constant>),
154 and converting from a physical value to Comedi's integer sample values
155 (<constant>COMEDI_FROM_PHYSICAL</constant>).
160 <section id="ref-enum-comedi-io-direction">
162 enum comedi_io_direction
167 enum comedi_io_direction
175 A <type>comedi_io_direction</type> is used to select between input or output. For example,
176 <function><link linkend="func-ref-comedi-dio-config">comedi_dio_config</link></function>
177 uses the <constant>COMEDI_INPUT</constant> and <constant>COMEDI_OUTPUT</constant> values to specify
178 whether a configurable digital i/o channel should be configured as an input
184 <section id="ref-enum-comedi-subdevice-type">
186 enum comedi_subdevice_type
191 enum comedi_subdevice_type {
192 COMEDI_SUBD_UNUSED, /* subdevice is unused by driver */
193 COMEDI_SUBD_AI, /* analog input */
194 COMEDI_SUBD_AO, /* analog output */
195 COMEDI_SUBD_DI, /* digital input */
196 COMEDI_SUBD_DO, /* digital output */
197 COMEDI_SUBD_DIO, /* digital input/output */
198 COMEDI_SUBD_COUNTER, /* counter */
199 COMEDI_SUBD_TIMER, /* timer */
200 COMEDI_SUBD_MEMORY, /* memory, EEPROM, DPRAM */
201 COMEDI_SUBD_CALIB, /* calibration DACs and pots*/
202 COMEDI_SUBD_PROC, /* processor, DSP */
203 COMEDI_SUBD_SERIAL, /* serial IO */
204 COMEDI_SUBD_PWM /* pulse width modulation */
209 The <type>comedi_subdevice_type</type> enumeration specifies the possible values for
210 a subdevice type. These values are used by the functions
211 <function><link linkend="func-ref-comedi-get-subdevice-type">comedi_get_subdevice_type</link></function> and
212 <function><link linkend="func-ref-comedi-find-subdevice-by-type">comedi_find_subdevice_by_type</link></function>.
219 <section id="datatypesstructures">
221 Data types and structures
224 This Section explains the data structures that users of the &comedi;
225 API are confronted with:
227 typedef struct comedi_devinfo_struct <link linkend="ref-type-comedi-devinfo">comedi_devinfo</link>;
228 typedef struct comedi_t_struct <link linkend="ref-type-comedi-t">comedi_t</link>;
229 typedef struct sampl_t_struct <link linkend="ref-type-sampl-t">sampl_t</link>;
230 typedef struct lsampl_t_struct <link linkend="ref-type-lsampl-t">lsampl_t</link>;
231 typedef struct comedi_sv_t_struct <link linkend="ref-type-comedi-sv-t">comedi_sv_t</link>;
232 typedef struct comedi_cmd_struct <link linkend="ref-type-comedi-cmd">comedi_cmd</link>;
233 typedef struct comedi_insn_struct <link linkend="ref-type-comedi-insn">comedi_insn</link>;
234 typedef struct comedi_range_struct <link linkend="ref-type-comedi-range">comedi_range</link>;
235 typedef struct comedi_krange_struct <link linkend="ref-type-comedi-krange">comedi_krange</link>;
236 typedef struct comedi_insnlist_struct <link linkend="ref-type-comedi-insnlist">comedi_insnlist</link>;
238 The data structures used in the implementation of the &comedi; drivers
239 are treated <link linkend="driverdatastructures">elsewhere</link>.
243 <section id="ref-type-comedi-devinfo">
249 The data type <type>comedi_devinfo</type> is used to store
250 information about a device. This structure is usually filled in
251 automatically when the driver is loaded (<quote>attached</quote>), so
252 programmers need not access this data structure directly.
254 typedef struct comedi_devinfo_struct comedi_devinfo;
256 struct comedi_devinfo_struct{
257 unsigned int version_code; // version number of the Comedi code
258 unsigned int n_subdevs; // number of subdevices on this device
259 char driver_name[COMEDI_NAMELEN];
260 char board_name[COMEDI_NAMELEN];
261 int read_subdevice; // index of subdevice whose buffer is read by read(), etc. on file descriptor from comedi_fileno() (negative means none)
262 int write_subdevice; // index of subdevice whose buffer is written by write(), etc. on file descriptor from comedi_fileno() (negatove means none).
272 <section id="ref-type-comedi-t">
278 The data type <type>comedi_t</type> is used to represent an
279 open &comedi; device:
281 typedef struct comedi_t_struct comedi_t;
283 A valid <type>comedi_t</type> pointer is returned by a
285 <function><link linkend="func-ref-comedi-open">comedi_open</link></function>,
286 and should be used for subsequent access to the device.
287 It is an opaque type, and pointers to type
288 <parameter>comedi_t</parameter>
289 should not be dereferenced by the application.
295 <section id="ref-type-sampl-t">
301 typedef unsigned short sampl_t;
305 The data type <type>sampl_t</type> is one
307 types used to represent data values in Comedilib. It is used in a few
308 places where a data type
309 shorter than <type><link linkend="ref-type-lsampl-t">lsampl_t</link></type> is
310 useful. On most architectures it is a 16-bit, unsigned integer.
314 Most drivers represent data transferred by <function>read</function> and
315 <function>write</function> functions using <type>sampl_t</type>.
316 Applications should check the subdevice flag
317 <constant>SDF_LSAMPL</constant> to determine if the subdevice uses
318 <type>sampl_t</type> or
319 <type><link linkend="ref-type-lsampl-t">lsampl_t</link></type>.
324 <section id="ref-type-lsampl-t">
330 typedef unsigned int lsampl_t;
335 <type><link linkend="ref-type-lsampl-t">lsampl_t</link></type>
336 is the data type typically used to represent
337 data values in Comedilib. On most architectures it is a 32-bit,
343 <section id="ref-type-comedi-trig">
345 comedi_trig (deprecated)
349 typedef struct comedi_trig_struct comedi_trig;
351 struct comedi_trig_struct{
352 unsigned int subdev; /* subdevice */
353 unsigned int mode; /* mode */
355 unsigned int n_chan; /* number of channels */
356 unsigned int *chanlist; /* channel/range list */
357 <link linkend="ref-type-sampl-t">sampl_t</link> *data; /* data list, size depends on subd flags */
358 unsigned int n; /* number of scans */
359 unsigned int trigsrc;
360 unsigned int trigvar;
361 unsigned int trigvar1;
362 unsigned int data_len;
363 unsigned int unused[3];
368 The <type>comedi_trig</type> structure is a control structure used by the
369 <constant>COMEDI_TRIG</constant> ioctl, an older method of communicating
370 instructions to the driver and hardware. Use of <type>comedi_trig</type> is
371 deprecated, and should not be used in new applications.
375 <section id="ref-type-comedi-sv-t">
377 comedi_sv_t (deprecated)
381 typedef struct comedi_sv_struct comedi_sv_t;
383 struct comedi_sv_struct{
385 unsigned int subdevice;
392 /* number of measurements to average (for ai) */
395 <link linkend="ref-type-lsampl-t">lsampl_t</link> maxdata;
400 The <type>comedi_sv_t</type> structure is used by the <function>comedi_sv_…</function>
401 functions to provide a simple method of accurately measuring
402 slowly varying inputs. See the relevant section for more
407 <section id="ref-type-comedi-cmd">
413 typedef struct comedi_cmd_struct comedi_cmd;
415 struct comedi_cmd_struct{
419 unsigned int start_src;
420 unsigned int start_arg;
422 unsigned int scan_begin_src;
423 unsigned int scan_begin_arg;
425 unsigned int convert_src;
426 unsigned int convert_arg;
428 unsigned int scan_end_src;
429 unsigned int scan_end_arg;
431 unsigned int stop_src;
432 unsigned int stop_arg;
434 unsigned int *chanlist;
435 unsigned int chanlist_len;
437 <link linkend="ref-type-sampl-t">sampl_t</link> *data;
438 unsigned int data_len;
443 More information on using commands can be found in the
444 <link linkend="commandsstreaming">command section</link>.
448 <section id="ref-type-comedi-insn">
454 typedef struct comedi_insn_struct comedi_insn;
456 struct comedi_insn_struct{
459 <link linkend="ref-type-lsampl-t">lsampl_t</link>*data;
461 unsigned int chanspec;
462 unsigned int unused[3];
467 Comedi instructions are described by the <type>comedi_insn</type> structure.
468 Applications send instructions to the driver in order to perform
469 control and measurement operations that are done immediately or
470 synchronously, i.e., the operations complete before program control
471 returns to the application. In particular, instructions cannot
472 describe acquisition that involves timers or external events.
476 The field insn determines the type of instruction that is sent
477 to the driver. Valid instruction types are:
483 <anchor id="insn-read"/>
484 <constant>INSN_READ</constant>
488 read values from an input channel
494 <anchor id="insn-write"/>
495 <constant>INSN_WRITE</constant>
499 write values to an output channel
505 <anchor id="insn-bits"/>
506 <constant>INSN_BITS</constant>
510 read/write values on multiple digital I/O channels
516 <anchor id="insn-config"/>
517 <constant>INSN_CONFIG</constant>
521 configure a subdevice
527 <anchor id="insn-gtod"/>
528 <constant>INSN_GTOD</constant>
532 read a timestamp, identical to <function>gettimeofday</function> except the seconds
533 and microseconds values are of type <type><link linkend="ref-type-lsampl-t">lsampl_t</link></type>.
539 <anchor id="insn-wait"/>
540 <constant>INSN_WAIT</constant>
544 wait a specified number of nanoseconds
551 The number of samples to read or write, or the size of the configuration
552 structure is specified by the field n, and the buffer for those
553 samples by data. The field subdev is the subdevice index
554 that the instruction is sent to. The field chanspec specifies
555 the channel, range, and analog reference (if applicable).
559 Instructions can be sent to drivers using
560 <function><link linkend="func-ref-comedi-do-insn">comedi_do_insn</link></function>.
561 Multiple instructions can be sent to drivers in the same system call using
562 <function><link linkend="func-ref-comedi-do-insnlist">comedi_do_insnlist</link></function>.
566 <section id="ref-type-comedi-range">
572 typedef struct comedi_range_struct comedi_range;
574 struct comedi_range_struct{
582 The <type>comedi_range</type> structure conveys part of the information
583 necessary to translate sample values to physical units, in particular,
584 the endpoints of the range and the physical unit type. The
585 physical unit type is specified by the field unit, which may
586 take the values <constant>UNIT_volt</constant> for volts,
587 <constant>UNIT_mA</constant> for milliamps,
588 or <constant>UNIT_none</constant> for unitless. The endpoints are specified by
589 the fields min and max.
593 <section id="ref-type-comedi-krange">
599 typedef struct comedi_krange_struct comedi_krange;
601 struct comedi_krange_struct{
609 The <type>comedi_krange</type> structure is used to transfer range information
610 between the driver and Comedilib, and should not normally be used
611 by applications. The structure conveys the same information as the
612 comedi_range structure, except the fields min and max
613 are integers, multiplied by a factor of 1000000 compared to the
614 counterparts in <type>comedi_range</type>.
618 In addition, <systemitem>kcomedilib</systemitem> uses the
619 <type>comedi_krange</type> structure in place
620 of the <type>comedi_range</type> structure.
625 <section id="ref-type-comedi-insnlist">
631 typedef struct comedi_insnlist_struct comedi_insnlist;
633 struct comedi_insnlist_struct{
634 unsigned int n_insns;
640 A <type>comedi_insnlist</type> structure is used to communicate
641 a list of instructions to the driver using the
642 <function><link linkend="func-ref-comedi-do-insnlist">comedi_do_insnlist</link></function>
649 <section id="ref-type-comedi-polynomial-t">
655 #define COMEDI_MAX_NUM_POLYNOMIAL_COEFFICIENTS 4
657 double coefficients[COMEDI_MAX_NUM_POLYNOMIAL_COEFFICIENTS];
658 double expansion_origin;
660 } comedi_polynomial_t;
664 A <type>comedi_polynomial_t</type> holds calibration data for a channel of a
665 subdevice. It is initialized by the
666 <function><link linkend="func-ref-comedi-get-hardcal-converter">comedi_get_hardcal_converter</link></function>
667 or <function><link linkend="func-ref-comedi-get-softcal-converter">comedi_get_softcal_converter</link></function>
668 calibration functions and is passed to the
669 <function><link linkend="func-ref-comedi-to-physical">comedi_to_physical</link></function>
670 and <function><link linkend="func-ref-comedi-from-physical">comedi_from_physical</link></function>
671 raw/physical conversion functions.
678 <section id="functionreference">
679 <title>Functions</title>
680 <xi:include href="funcref.xml"/>
681 <xi:include href="command_funcref.xml"/>
682 <xi:include href="calibration_funcref.xml"/>
683 <xi:include href="dio_funcref.xml"/>
684 <xi:include href="error_funcref.xml"/>
685 <xi:include href="extensions_funcref.xml"/>
686 <xi:include href="deprecated_funcref.xml"/>
688 <xi:include href="drivers.xml"/>