1 <!-- <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V3.1//EN" -->
3 <section id="comedi-comedilib-h">
5 Headerfiles: <filename>comedi.h</filename> and <filename>comedilib.h</filename>
9 All <link linkend="writingprograms">application programs</link> must
10 include the header file <filename>comedilib.h</filename>. (This file
11 itself includes <filename>comedi.h</filename>.) They contain the full
12 interface of &comedi;: defines, function prototypes, data structures.
15 The following Sections give more details.
20 <section id="constantsmacros">
25 <section id="ref-macro-CR-PACK">
31 CR_PACK is used to initialize the elements of the
32 <parameter>chanlist</parameter> array in the
33 <link linkend="ref-type-comedi-cmd">comedi_cmd</link> data structure,
34 and the <parameter>chanspec</parameter> member of the
35 <link linkend="ref-type-comedi-insn">comedi_insn</link> structure.
39 #define CR_PACK(chan,rng,aref) ( (((aref)&0x3)<<24) | (((rng)&0xff)<<16) | (chan) )
43 The <parameter>chan</parameter> argument is the channel you wish to
44 use, with the channel numbering starting at zero.
48 The range <parameter>rng</parameter> is an index, starting at zero,
49 whose meaning is device dependent. The
50 <link linkend="func-ref-comedi-get-n-ranges">comedi_get_n_ranges()</link>
52 <link linkend="func-ref-comedi-get-range">comedi_get_range()</link>
53 functions are useful in discovering information about the available
58 The <parameter>aref</parameter> argument indicates what reference you
59 want the device to use. It can be any of the following:
62 <term>AREF_GROUND <anchor id="aref-ground"> </term>
65 is for inputs/outputs referenced to ground.
70 <term>AREF_COMMON <anchor id="aref-common"> </term>
73 is for a <quote>common</quote> reference (the low inputs of all the
74 channels are tied together, but are isolated from ground).
79 <term>AREF_DIFF <anchor id="aref-diff"> </term>
82 is for differential inputs/outputs.
87 <term>AREF_OTHER <anchor id="aref-other"> </term>
90 is for any reference that does not fit into the above categories.
95 Particular drivers may or may not use the AREF flags. If they are
96 not supported, they are silently ignored.
100 <section id="ref-macro-RANGE-LENGTH">
102 RANGE_LENGTH (deprecated)
106 Rangetype values are library-internal tokens that represent an
107 array of range information structures. These numbers are primarily
108 used for communication between the kernel and library.
112 The RANGE_LENGTH() macro returns the length of the array that is
113 specified by the rangetype token.
117 The RANGE_LENGTH() macro is deprecated, and should not be used in
118 new applications. It is scheduled to be removed from the header
119 file at version 1.0. Binary compatibility may be broken for version
126 <section id="datatypesstructures">
128 Data Types and Structures
131 This Section explains the data structures that users of the &comedi;
132 API are confronted with:
134 typedef struct subdevice_struct <link linkend="ref-type-subdevice-struct">subdevice_struct</link>:
135 typedef struct comedi_devinfo_struct <link linkend="ref-type-comedi-devinfo">comedi_devinfo</link>;
136 typedef struct comedi_t_struct <link linkend="ref-type-comedi-t">comedi_t</link>;
137 typedef struct sampl_t_struct <link linkend="ref-type-sampl-t">sampl_t</link>;
138 typedef struct lsampl_t_struct <link linkend="ref-type-lsampl-t">lsampl_t</link>;
139 typedef struct comedi_sv_t_struct <link linkend="ref-type-comedi-sv-t">comedi_sv_t</link>;
140 typedef struct comedi_cmd_struct <link linkend="ref-type-comedi-cmd">comedi_cmd</link>;
141 typedef struct comedi_insn_struct <link linkend="ref-type-comedi-insn">comedi_insn</link>;
142 typedef struct comedi_range_struct <link linkend="ref-type-comedi-range">comedi_range</link>;
143 typedef struct comedi_krange_struct <link linkend="ref-type-comedi-krange">comedi_krange</link>;
144 typedef struct comedi_insnlist_struct <link linkend="ref-type-comedi-insnlist">comedi_insnlist</link>;
146 The data structures used in the implementation of the &comedi; drivers
147 are treated <link linkend="driverdatastructures">elsewhere</link>.
150 <section id="ref-type-subdevice-struct">
156 The data type <parameter>subdevice_struct</parameter> is used to store
157 information about a subdevice. This structure is usually filled in
158 automatically when the driver is loaded (<quote>attached</quote>), so
159 programmers need not access this data structure directly.
161 typedef struct subdevice_struct <anchor id="ref-type-subdevice">subdevice;
163 struct subdevice_struct{
166 unsigned int subd_flags;
167 unsigned int timer_type;
168 unsigned int len_chanlist;
169 <link linkend="ref-type-lsampl-t">lsampl_t</link> maxdata;
171 unsigned int range_type;
173 <link linkend="ref-type-lsampl-t">lsampl_t</link> *maxdata_list;
174 unsigned int *range_type_list;
175 unsigned int *flags_list;
177 <link linkend="ref-type-comedi-range">comedi_range</link> *rangeinfo;
178 <link linkend="ref-type-comedi-range">ccomedi_range</link> **rangeinfo_list;
180 unsigned int has_cmd;
181 unsigned int has_insn_bits;
184 <link linkend="ref-type-comedi-cmd">comedi_cmd</link> *cmd_mask;
186 <link linkend="ref-type-comedi-cmd">comedi_cmd</link> *cmd_timed;
195 <section id="ref-type-comedi-devinfo">
201 The data type <parameter>comedi_devinfo</parameter> is used to store
202 information about a device. This structure is usually filled in
203 automatically when the driver is loaded (<quote>attached</quote>), so
204 programmers need not access this data structure directly.
206 typedef struct comedi_devinfo_struct comedi_devinfo;
208 struct comedi_devinfo_struct{
209 unsigned int version_code; // version number of the Comedi code
210 unsigned int n_subdevs; // number of subdevices on this device
211 char driver_name[COMEDI_NAMELEN];
212 char board_name[COMEDI_NAMELEN];
213 int read_subdevice; // number of read devices
214 int write_subdevice; // number of write devices
224 <section id="ref-type-comedi-t">
230 The data type <parameter>comedi_t</parameter> is used to represent an
231 open &comedi; device:
233 typedef struct comedi_t_struct comedi_t;
235 struct comedi_t_struct{
236 int magic; // driver-specific magic number, for identification
237 int fd; // file descriptor, for open() and close()
238 int n_subdevices; // number of subdevices on this device
239 <link linkend="ref-type-comedi-devinfo">comedi_devinfo</link> devinfo;
240 <link linkend="ref-type-subdevice">subdevice</link> *subdevices; // pointer to subdevice list
241 // filled in automatically at load time
242 unsigned int has_insnlist_ioctl; // can process <link linkend="anchor.instruction.list">instruction lists</link>
243 unsigned int has_insn_ioctl; // can process <link linkend="instructions">instructions</link>
246 A valid <parameter>comedi_t</parameter> pointer is returned by a
248 <link linkend="func-ref-comedi-open">comedi_open()</link>,
249 and should be used for subsequent access to the device.
250 It is a transparent type, and pointers to type
251 <parameter>comedi_t</parameter>
252 should not be dereferenced by the application.
258 <section id="ref-type-sampl-t">
264 typedef unsigned short sampl_t;
268 The data type <link linkend="ref-type-sampl-t">sampl_t</link> is one
270 types used to represent data values in Comedilib. It is used in a few
271 places where a data type
272 shorter than <link linkend="ref-type-lsampl-t">lsampl_t</link> is
273 useful. On most architectures,
274 <link linkend="ref-type-sampl-t">sampl_t</link>
275 is defined to be <parameter>uint16</parameter>.
279 Most drivers represent data transferred by <function>read()</function> and
280 <function>write()</function> using
281 <link linkend="ref-type-sampl-t">sampl_t</link>.
282 Applications should check the subdevice flag
283 SDF_LSAMPL to determine if the subdevice uses
284 <link linkend="ref-type-sampl-t">sampl_t</link> or
285 <link linkend="ref-type-lsampl-t">lsampl_t</link>.
290 <section id="ref-type-lsampl-t">
296 typedef unsigned int lsampl_t;
301 <link linkend="ref-type-lsampl-t">lsampl_t</link>
302 is the data type typically used to represent
303 data values in libcomedi. On most architectures,
304 <link linkend="ref-type-lsampl-t">lsampl_t</link>
305 is defined to be uint32.
310 <section id="ref-type-comedi-trig">
312 comedi_trig (deprecated)
316 typedef struct comedi_trig_struct comedi_trig;
318 struct comedi_trig_struct{
319 unsigned int subdev; /* subdevice */
320 unsigned int mode; /* mode */
322 unsigned int n_chan; /* number of channels */
323 unsigned int *chanlist; /* channel/range list */
324 <link linkend="ref-type-sampl-t">sampl_t</link> *data; /* data list, size depends on subd flags */
325 unsigned int n; /* number of scans */
326 unsigned int trigsrc;
327 unsigned int trigvar;
328 unsigned int trigvar1;
329 unsigned int data_len;
330 unsigned int unused[3];
335 The comedi_trig structure is a control structure used by the
336 COMEDI_TRIG ioctl, an older method of communicating
337 instructions to the driver and hardware. Use of comedi_trig is
338 deprecated, and should not be used in new applications.
342 <section id="ref-type-comedi-sv-t">
348 typedef struct comedi_sv_struct comedi_sv_t;
350 struct comedi_sv_struct{
352 unsigned int subdevice;
359 /* number of measurements to average (for ai) */
362 <link linkend="ref-type-lsampl-t">lsampl_t</link> maxdata;
367 The comedi_sv_t structure is used by the comedi_sv_*()
368 functions to provide a simple method of accurately measuring
369 slowly varying inputs. See the relevant section for more
374 <section id="ref-type-comedi-cmd">
380 typedef struct comedi_cmd_struct comedi_cmd;
382 struct comedi_cmd_struct{
386 unsigned int start_src;
387 unsigned int start_arg;
389 unsigned int scan_begin_src;
390 unsigned int scan_begin_arg;
392 unsigned int convert_src;
393 unsigned int convert_arg;
395 unsigned int scan_end_src;
396 unsigned int scan_end_arg;
398 unsigned int stop_src;
399 unsigned int stop_arg;
401 unsigned int *chanlist;
402 unsigned int chanlist_len;
404 <link linkend="ref-type-sampl-t">sampl_t</link> *data;
405 unsigned int data_len;
410 More information on using commands can be found in the
415 <section id="ref-type-comedi-insn">
421 typedef struct comedi_insn_struct comedi_insn;
423 struct comedi_insn_struct{
426 <link linkend="ref-type-lsampl-t">lsampl_t</link>*data;
428 unsigned int chanspec;
429 unsigned int unused[3];
434 Comedi instructions are described by the comedi_insn structure.
435 Applications send instructions to the driver in order to perform
436 control and measurement operations that are done immediately or
437 synchronously, i.e., the operations complete before program control
438 returns to the application. In particular, instructions cannot
439 describe acquisition that involves timers or external events.
443 The field insn determines the type of instruction that is sent
444 to the driver. Valid instruction types are:
450 <anchor id="insn-read">
455 read values from an input channel
461 <anchor id="insn-write">
466 write values to an output channel
472 <anchor id="insn-bits">
477 read/write values on multiple digital I/O channels
483 <anchor id="insn-config">
488 configure a subdevice
494 <anchor id="insn-gtod">
499 read a timestamp, identical to gettimeofday()
505 <anchor id="insn-wait">
510 wait a specified number of nanoseconds
517 The number of samples to read or write, or the size of the configuration
518 structure is specified by the field n, and the buffer for those
519 samples by data. The field subdev is the subdevice index
520 that the instruction is sent to. The field chanspec specifies
521 the channel, range, and analog reference (if applicable).
525 Instructions can be sent to drivers using comedi_do_insn().
526 Multiple instructions can be sent to drivers in the same system
527 call using comedi_do_insnlist().
531 <section id="ref-type-comedi-range">
537 typedef struct comedi_range_struct comedi_range;
539 struct comedi_range_struct{
547 The comedi_range structure conveys part of the information
548 necessary to translate sample values to physical units, in particular,
549 the endpoints of the range and the physical unit type. The
550 physical unit type is specified by the field unit, which may
551 take the values UNIT_volt for volts, UNIT_mA for milliamps,
552 or UNIT_none for unitless. The endpoints are specified by
553 the fields min and max.
557 <section id="ref-type-comedi-krange">
563 typedef struct comedi_krange_struct comedi_krange;
565 struct comedi_krange_struct{
573 The comedi_krange structure is used to transfer range information
574 between the driver and Comedilib, and should not normally be used
575 by applications. The structure conveys the same information as the
576 comedi_range structure, except the fields min and max
577 are integers, multiplied by a factor of 1000000 compared to the
578 counterparts in comedi_range.
582 In addition, kcomedilib uses the comedi_krange structure in place
583 of the comedi_range structure.
588 <section id="ref-type-comedi-insnlist">
594 typedef struct comedi_insnlist_struct comedi_insnlist;
596 struct comedi_insnlist_struct{
597 unsigned int n_insns;
603 An instruction list (insnlist) structure is used to communicate
604 a list of instructions.