Should be understandable. Open the device, get the data,
print it out. This is basically the guts of <tt>demo/inp.c</tt>,
-without error checking or fancy options. Including all
-the appropriate headers is sometimes a little tricky.
+without error checking or fancy options.
Compile it using
<tscreen><verb>
cc tut1.c -lcomedi -o tut1
</verb></tscreen>
-Hopefully it works.
-
A few notes: The range variable tells comedi which gain
to use when measuring an analog voltage. Since we don't
know (yet) which numbers are valid, or what each means,
question is: "How do I do this in a device-independent
manner?"
-For each subdevice, the comedi kernel module keeps a
-'range_type' variable. This variable contains the number
-of available ranges (i.e., gains) that you can select,
-along with an offset in a list of range information
-structures. If you know the range_type variable, you
-can use these macros:
+Most devices give you a choice of gain and unipolar/bipolar
+input, and Comedi allows you to select which of these to
+use. This parameter is called the "range parameter", since
+it specifies the "input range" for analog input (or "output range"
+analog output.) The range parameter represents both the gain
+and the unipolar/bipolar aspects.
+
+Comedi keeps the number of available ranges and the largest
+sample value for each subdevice/channel combination. (Some
+devices allow different input/output ranges for different
+channels in a subdevice.)
+
+The largest sample value can be found using the function:
- RANGE_OFFSET(range_type)
- RANGE_LENGTH(range_type)
+ comedi_get_maxdata()
-to extract such information. However, you want the
-actual voltage information, not some integer offset
-in a table. Rather than messing with the library
-internals, use the function
+The number of available ranges can be found using the function:
+
+ comedi_get_n_ranges()
+
+For each value of the range parameter for a particular
+subdevice/channel, you can get range information using the
+function:
ptr=comedi_get_range(comedi_file,subdevice,channel,
range)
}comedi_range;
</verb></tscreen>
-As you might expect, ptr[range] is for range 'range',
-which you provided to comedi_data_read() above. 'min' represents
+The structure element 'min' represents
the voltage corresponding to comedi_data_read() returning 0,
and 'max' represents comedi_data_read() returning 'maxdata',
(i.e., 4095 for 12 bit A/C converters, 65535 for 16 bit,
data=comedi_from_phys(it,volts,range,maxdata);
</verb></tscreen>
-You probably noticed (and were worried) that we haven't
-discussed how to determine maxdata and range_type. Well,
-you could ask the kernel this information each time you need
-it, but since there are other variables, special cases,
-and several subdevices to worry about, it would be nice
-if the library could take care of this... (read on...)
-
<p>
<sect1>Another section
calls <tt>open()</tt>, like we did explicitly in a previous
section, but also fills the <tt>comedi_t</tt> structure with
lots of goodies -- information that we will need to use
-soon.
+soon.
Specifically, we needed to know maxdata for a specific
subdevice/channel. How about:
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+ <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
+ <TITLE>Comedi Documentation: Libcomedi Reference</TITLE>
+
+ <LINK HREF="comedilib_reference.html#toc1" REL=contents>
+</HEAD>
+<BODY>
+Next
+Previous
+<A HREF="comedilib_reference.html#toc1">Contents</A>
+<HR>
+<H2><A NAME="s1">1. Libcomedi Reference</A></H2>
+
+<P>
+<P>
+<H2><A NAME="ss1.1">1.1 Constants and Macros</A>
+</H2>
+
+<P>
+<P>
+<P>
+<H3>RANGE_LENGTH() <I>(deprecated)</I></H3>
+
+<P>
+<A NAME="RANGE_LENGTH"></A> <P><CODE>RANGE_LENGTH(rangetype)</CODE>
+<P>
+<P>Rangetype values are library-internal tokens that represent an
+array of range information structures. These numbers are primarily
+used for communication between the kernel and library.
+<P>
+<P>The RANGE_LENGTH() macro returns the length of the array that is
+specified by the rangetype token.
+<P>
+<P>The RANGE_LENGTH() macro is deprecated, and should not be used in
+new applications. It is scheduled to be removed from the header
+file at version 1.0. Binary compatibility may be broken for version
+1.1.
+<P>
+<P>
+<P>
+<H2><A NAME="ss1.2">1.2 Data Types and Structures</A>
+</H2>
+
+<P>
+<H3><A NAME="comedi_t"></A> comedi_t</H3>
+
+<P>The data type <CODE>comedi_t</CODE> is used to represent an open Comedi
+device. A valid <CODE>comedi_t</CODE> pointer is returned by a successful
+call to <CODE>comedi_open()</CODE>, and should be used for subsequent
+access to the device.
+It is a transparent type, and pointers to type <CODE>comedi_t</CODE>
+should not be dereferenced.
+<P>
+<P>
+<P>
+<H3><A NAME="sampl_t"></A> sampl_t</H3>
+
+<P>The data type <CODE>sampl_t</CODE> is one of the generic types used to represent
+data values in libcomedi. It is used in a few places where a shorter
+data type is useful, but is limited to 16 bits on the i386 architecture.
+<P>
+<P>
+<P>
+<H3><A NAME="lsampl_t"></A> lsampl_t</H3>
+
+<P>The data type <CODE>lsampl_t</CODE> is one of the generic types used to represent
+data values in libcomedi. It is currently defined to be <CODE>unsigned int</CODE>.
+<P>
+<P>
+<P>
+<P>
+<P>
+<H3><A NAME="comedi_trig_struct"></A> comedi_trig_struct <I>(deprecated)</I></H3>
+
+<P>
+<P>The <CODE>comedi_trig</CODE> structure
+<P>
+<BLOCKQUOTE><CODE>
+<PRE>
+struct comedi_trig_struct{
+ unsigned int subdev; /* subdevice */
+ unsigned int mode; /* mode */
+ unsigned int flags;
+ unsigned int n_chan; /* number of channels */
+ unsigned int *chanlist; /* channel/range list */
+ sampl_t *data; /* data list, size depends on subd flags */
+ unsigned int n; /* number of scans */
+ unsigned int trigsrc;
+ unsigned int trigvar;
+ unsigned int trigvar1;
+ unsigned int data_len;
+ unsigned int unused[3];
+}
+</PRE>
+</CODE></BLOCKQUOTE>
+<P>The <CODE>comedi_trig</CODE> structure is a control structure used by the
+COMEDI_TRIG ioctl, an older method of communicating
+instructions to the driver and hardware. Use of Comedi triggers is
+deprecated, and should not be used in new applications.
+<P>
+<P>
+<P>
+<H3><A NAME="comedi_sv_t"></A> comedi_sv_t</H3>
+
+<P>
+<P>
+<BLOCKQUOTE><CODE>
+<PRE>
+struct comedi_sv_struct{
+ comedi_t *dev;
+ unsigned int subdevice;
+ unsigned int chan;
+
+ /* range policy */
+ int range;
+ int aref;
+
+ /* number of measurements to average (for ai) */
+ int n;
+
+ lsampl_t maxdata;
+}
+</PRE>
+</CODE></BLOCKQUOTE>
+<P>The <CODE>comedi_sv_t</CODE> structure is used by the <CODE>comedi_sv_*()</CODE>
+functions to provide a simple method of accurately measuring
+slowly varying inputs. See the relevant section for more
+details.
+<P>
+<P>
+<P>
+<H2><A NAME="ss1.3">1.3 Functions</A>
+</H2>
+
+<P>
+<P>
+<H3><A NAME="comedi_close"></A> comedi_close()</H3>
+
+<P>
+<P><CODE>void comedi_close(comedi_t *it);</CODE>
+<P>
+<P>Closes a device previously opened by comedi_open().
+<P>
+<P>The return type of this function will change to <CODE>int</CODE>, in
+order to match <CODE>fclose</CODE>.
+<P>
+<P>Source: <CODE>/lib/comedi.c</CODE>
+<P>
+<P>
+<H3><A NAME="comedi_data_read"></A> comedi_data_read()</H3>
+
+<P>
+<P><CODE>int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
+unsigned int range,unsigned int aref,lsampl_t *data);</CODE>
+<P>
+<P>Reads a single sample on the channel that
+is specified by the comedi device <CODE>it</CODE>, the
+subdevice <CODE>subd</CODE>, and the channel <CODE>chan</CODE>.
+For the A/D conversion (if appropriate),
+the device is configured to use range specification
+<CODE>range</CODE> and (if appropriate) analog reference type
+<CODE>aref</CODE>. Analog reference types that are not supported
+by the device are silently ignored.
+<P>
+<P><CODE>comedi_data_read()</CODE> reads one data value from
+the specified channel and places the
+data value that is read in the location pointed to by
+<CODE>data</CODE>.
+<P>
+<P>On sucess, <CODE>comedi_data_read()</CODE> returns 0. If there is an
+error, -1 is returned.
+<P>
+<P>Valid analog reference numbers are:
+<P>
+<UL>
+<LI>AREF_GROUND Reference to analog ground</LI>
+<LI>AREF_COMMON Reference to analog common</LI>
+<LI>AREF_DIFF Differential reference</LI>
+<LI>AREF_OTHER Board-specific meaning</LI>
+</UL>
+<P>Valid data values returned by these function is an unsigned integer
+less than or equal to <CODE>maxdata</CODE>, which is channel-dependent.
+Conversion of these data value to physical units can be performed
+by <CODE>
+<A HREF="#comedi_to_phys">comedi_to_phys()</A></CODE>.
+<P>Source: <CODE>/lib/data.c</CODE>
+<P>
+<P>
+<H3>comedi_data_write()</H3>
+
+<P>
+<P><CODE>int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
+unsigned int range,unsigned int aref,lsampl_t data);</CODE>
+<P>
+<P>Writes a single sample on the channel that
+is specified by the comedi device <CODE>it</CODE>, the
+subdevice <CODE>subd</CODE>, and the channel <CODE>chan</CODE>.
+For the D/A conversion (if appropriate), the device is
+configured to use range specification
+<CODE>range</CODE> and (if appropriate) analog reference type
+<CODE>aref</CODE>. Analog reference types that are not supported
+by the device are silently ignored.
+<P><CODE>comedi_data_write()</CODE> writes the data value
+specified by the argument <CODE>data</CODE> to
+the specified channel.
+<P>On sucess, <CODE>comedi_data_write()</CODE> returns 0. If there is an error, -1 is
+returned.
+<P>Valid analog reference numbers are:
+<P>
+<UL>
+<LI>AREF_GROUND Reference to analog ground</LI>
+<LI>AREF_COMMON Reference to analog common</LI>
+<LI>AREF_DIFF Differential reference</LI>
+<LI>AREF_OTHER Board-specific meaning</LI>
+</UL>
+<P>Valid data values used by these functions is an unsigned integer
+less than or equal to <CODE>maxdata</CODE>, which is channel-dependent.
+Conversion of physical units to these data value can be performed
+by <CODE>
+<A HREF="#comedi_from_phys">comedi_from_phys()</A></CODE>.
+<P>Source: <CODE>/lib/data.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_dio_bitfield();</H3>
+
+<P><CODE>int comedi_dio_bitfield(comedi_t *it,unsigned int subd,unsigned
+int write_mask,unsigned int *bits);</CODE>
+<P>
+<P>The function <CODE>comedi_dio_bitfield()</CODE> allows multiple channels to
+be read simultaneously from a digital input or digital I/O device.
+The parameter <CODE>write_mask</CODE> and the value pointed to by <CODE>bits</CODE>
+are interpreted as bit fields, with the least significant bit
+representing channel 0. For each bit in <CODE>write_mask</CODE> that is
+set, the cooresponding bit in <CODE>*bits</CODE> is written to the digital
+output channel. Each digital input channel is read, and the result
+placed in the approprate bits in <CODE>*bits</CODE>.
+<P>
+<P>The current implementation reads and writes bits using separate
+system calls, which is not ideal. When the kernel driver supports
+simultaneous reading/writing, this will be fixed in the library.
+<P>
+<P>It should be noted that it is not possible to access channels
+greater than 31 using this function.
+<P>
+<P>Source: <CODE>/lib/dio.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_dio_config()</H3>
+
+<P><CODE>int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned
+int chan,unsigned int dir);</CODE>
+<P>
+<P>The function <CODE>comedi_dio_config</CODE> configures individual channels
+in a digital I/O subdevice to be either input or output, depending
+on the value of parameter <CODE>dir</CODE>. Depending on the capabilities
+of the hardware device, multiple channels may be affected by
+a single call to <CODE>comedi_dio_config</CODE>.
+<P>
+<P>Valid directions are:
+<UL>
+<LI> COMEDI_INPUT</LI>
+<LI> COMEDI_OUTPUT</LI>
+</UL>
+<P>Source: <CODE>/lib/dio.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_dio_read()</H3>
+
+<P><CODE>int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int
+chan,unsigned int *bit);</CODE>
+<P>
+<P>The function reads the status of channel <CODE>chan</CODE> belonging to the digital
+input subdevice <CODE>subd</CODE> of device <CODE>it</CODE>. The result, 0 or 1, is stored
+in bit. Returns -1 on failure.
+<P>
+<P>This function is equivalent to <CODE>comedi_data_read(it,subd,chan,0,0,bit)</CODE>.
+<P>
+<P>Source: <CODE>/lib/dio.c</CODE>
+<P>
+<P>
+<H3>comedi_dio_write()</H3>
+
+<P><CODE>int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned
+int chan,unsigned int bit);</CODE>
+<P>
+<P>The function writes the value of <CODE>bit</CODE>, 0 or 1, to channel <CODE>chan</CODE>,
+belonging to the digital output device <CODE>subd</CODE> of device <CODE>it</CODE>. Returns
+-1 on failure.
+<P>
+<P>Source: <CODE>/lib/dio.c</CODE>
+<P>
+<P>
+<H3>comedi_fileno()</H3>
+
+<P>
+<P><CODE>int comedi_fileno(comedi_t *it);</CODE>
+<P>
+<P>The function <CODE>comedi_fileno</CODE>
+returns the integer descriptor for the handle <CODE>it</CODE>. It
+is equivalent to the standard function <CODE>fileno</CODE>. If
+<CODE>it</CODE> is an invalid <CODE>comedi_t</CODE> pointer, the function
+returns -1 and sets the appropriate libcomedi error value.
+<P>Source: <CODE>/lib/comedi.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_find_range()</H3>
+
+<P>
+<P><CODE>int comedi_find_range(comedi_t *it, unsigned int subdevice, unsigned
+int chan, unsigned int unit, double min, double max);</CODE>
+<P>
+<P>The function <CODE>comedi_find_range</CODE> tries to
+locate the optimal (smallest) range for the channel <CODE>chan</CODE>
+belonging to a <CODE>subdevice</CODE> of the comedi device <CODE>it</CODE>,
+that includes both <CODE>min</CODE> and <CODE>max</CODE> in <CODE>units</CODE>.
+If it finds a matching range, it returns its index. If no
+matching range is available, it returns -1.
+<P>
+<P>Valid units are:
+<P>
+<UL>
+<LI>UNIT_volt </LI>
+<LI>UNIT_mA</LI>
+<LI>UNIT_none</LI>
+</UL>
+<P>Source: <CODE>/lib/range.c</CODE>
+<P>
+<P>
+<P>
+<H3><A NAME="comedi_errno"></A> comedi_errno()</H3>
+
+<P><CODE>int comedi_errno(void);</CODE>
+<P>
+<P>The function <CODE>comedi_errno()</CODE>
+returns an integer describing the most recent comedilib error. This
+integer may be used as the <CODE>errnum</CODE> parameter for
+<CODE>
+<A HREF="#comedi_strerror">comedi_strerror()</A></CODE>.
+<P>When a libcomedi function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<CODE>comedi_errno()</CODE>. This error number can be
+converted to a human-readable form by the functions
+<CODE>
+<A HREF="#comedi_perror">comedi_perror()</A></CODE>
+and <CODE>
+<A HREF="#comedi_strerror">comedi_strerror()</A></CODE>.
+<P>These functions are intended to mimic the behavior of the
+standard C library functions <CODE>perror()</CODE>,
+<CODE>strerror</CODE>, and <CODE>errno()</CODE>. In particular,
+libcomedi functions sometimes return an error that is generated
+by the C library; the Comedi error message in this case
+is the same as the C library.
+<P>Source: <CODE>/lib/error.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_find_subdevice_by_type()</H3>
+
+<P>
+<P><CODE>int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int
+start_subdevice);</CODE>
+<P>
+<P>The function <CODE>comedi_find_subdevice_by_type</CODE> tries to
+locate a subdevice belonging to comedi device <CODE>it</CODE>,
+having type <CODE>type</CODE>, starting with the subdevice
+<CODE>start_subdevice</CODE>. If it finds the requested subdevice,
+it returns its index. If it does not locate the requested
+subdevice, it returns -1 and sets the comedi error number to
+"subdevice not found". If there is an error, the function
+returns -1 and sets the appropriate error.
+<P>
+<P>For subdevice types, see the manual page for the function
+<CODE>
+<A HREF="#comedi_get_subdevice_type">comedi_get_subdevice_type()</A></CODE>.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H3><A NAME="comedi_from_phys"></A> comedi_from_phys()</H3>
+
+<P>
+<P><CODE>lsampl_t comedi_from_phys(double data, comedi_range *rng,
+lsampl_t maxdata);</CODE>
+<P>Converts data given in physical units (<CODE>data</CODE>) into sample values
+(lsampl_t, between 0 and maxdata). The parameter <CODE>rng</CODE>
+represents the conversion information to use, and the parameter
+<CODE>maxdata</CODE> represents the maximum possible data value for the
+channel that the data will be written to.
+<P>
+<P>Source: <CODE>/lib/range.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_get_board_name()</H3>
+
+<P>
+<P><CODE>char *comedi_get_board_name(comedi_t *it);</CODE>
+<P>The function <CODE>comedi_get_board_name</CODE> returns a pointer
+to a string containing the name of the device. This pointer is
+valid until the comedi descriptor <CODE>it</CODE> is closed. This
+function returns <CODE>NULL</CODE> if there is an error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_get_driver_name()</H3>
+
+<P>
+<P><CODE>char *comedi_get_driver_name(comedi_t *it);</CODE>
+<P>The function <CODE>comedi_get_driver_name</CODE> returns a pointer
+to a string containing the name of the driver being used by comedi
+for the comedi device represented by <CODE>it</CODE>. This pointer is
+valid until the comedi descriptor <CODE>it</CODE> is closed. This
+function returns <CODE>NULL</CODE> if there is an error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_get_maxdata()</H3>
+
+<P>
+<P><CODE>lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int
+subdevice,unsigned int chan);</CODE>
+<P>
+<P>The function <CODE>comedi_get_maxdata()</CODE> returns the maximum
+valid data value for channel <CODE>chan</CODE> of subdevice
+<CODE>subdevice</CODE> belonging to the comedi device <CODE>it</CODE>
+This function returns 0 on error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_get_n_channels()</H3>
+
+<P>
+<P><CODE>int comedi_get_n_channels(comedi_t *it,unsigned int subdevice);</CODE>
+<P>The function <CODE>comedi_get_n_channels()</CODE> returns the number
+of channels of the subdevice belonging to the comedi device <CODE>it</CODE>
+and having index <CODE>subdevice</CODE>. This function returns -1 on error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_get_n_ranges()</H3>
+
+<P>
+<P><CODE>int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice, unsigned int
+chan);</CODE>
+<P>The function <CODE>comedi_get_n_ranges()</CODE> returns the number
+of ranges of the channel <CODE>chan</CODE> belonging to the <CODE>subdevice</CODE>
+of the comedi device <CODE>it</CODE>. This function returns -1 on error.
+<P>Source: <CODE>/lib/range.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_get_n_subdevices()</H3>
+
+<P>
+<P><CODE>int comedi_get_n_subdevices(comedi_t *it);</CODE>
+<P>The function <CODE>comedi_get_n_subdevices</CODE> returns the
+number of subdevices associated with the comedi descriptor
+<CODE>it</CODE>, or -1 if there is an error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_get_range()</H3>
+
+<P>
+<P><CODE>comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,unsigned int chan,unsigned int
+range);</CODE>
+<P>The function <CODE>comedi_get_range</CODE> returns a pointer to a
+comedi_range structure that contains information that can be used to
+convert sample values to or from physical units. The pointer is valid
+until the comedi device <CODE>it</CODE> is closed. If there is an
+error, NULL is returned.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<H3>comedi_get_rangetype()</H3>
+
+<P>
+<P><CODE>int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,unsigned int
+chan);</CODE>
+<P>The function <CODE>comedi_get_rangetype()</CODE> returns an integer
+that represents the number of range specifications available for a
+particular channel <CODE>chan</CODE> of the subdevice <CODE>subdevice</CODE>, as well as a conversion table to convert sample
+values to/from physical units.
+<P>The macro
+<CODE>RANGE_LENGTH(rangetype)</CODE>
+can be used to determine the number of range specifications for a given
+range type.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<H3><A NAME="comedi_get_subdevice_type"></A> comedi_get_subdevice_type()</H3>
+
+<P>
+<P><CODE>int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice);</CODE>
+<P>The function <CODE>comedi_get_subdevice_type()</CODE> returns an
+integer describing the type of subdevice that belongs to the comedi
+device <CODE>it</CODE> and has the index <CODE>subdevice</CODE>. The
+function returns -1 is there is an error.
+<P>Valid subdevice types are:
+<P>
+<UL>
+<LI><CODE>COMEDI_SUBD_UNUSED</CODE>
+Subdevice has no functionality, i.e., a place-holder.</LI>
+<LI><CODE>COMEDI_SUBD_AI</CODE> Analog input</LI>
+<LI><CODE>COMEDI_SUBD_AO</CODE> Analog output</LI>
+<LI><CODE>COMEDI_SUBD_DI</CODE> Digital input</LI>
+<LI><CODE>COMEDI_SUBD_DO</CODE> Digital output</LI>
+<LI><CODE>COMEDI_SUBD_DIO</CODE>
+Digital input/output. Channels are configurable as to whether they
+are inputs or outputs.</LI>
+<LI><CODE>COMEDI_SUBD_COUNTER</CODE> Counter</LI>
+<LI><CODE>COMEDI_SUBD_TIMER</CODE> Timer</LI>
+<LI><CODE>COMEDI_SUBD_MEMORY</CODE>
+Memory, e.g., EEPROM or dual-ported RAM</LI>
+<LI><CODE>COMEDI_SUBD_CALIB</CODE>
+Calibration DACs</LI>
+<LI><CODE>COMEDI_SUBD_PROC</CODE>
+Processor or DSP</LI>
+</UL>
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<H3>comedi_get_timer() <I>(deprecated)</I></H3>
+
+<P>
+<P><CODE>int comedi_get_timer(comedi_t *it,unsigned int subdev, double
+freq,unsigned int *trigvar, double *actual_freq);</CODE>
+<P>
+<P>The function <CODE>comedi_get_timer</CODE> converts the frequency <CODE>freq</CODE>
+to a number suitable to send to the driver in a <CODE>comedi_trig</CODE>
+structure. This function remains for compatibility with very
+old versions of Comedi, that converted sampling rates to timer
+values in the libary. This conversion is now done in the kernel,
+and every device has the timer type <CODE>nanosec_timer</CODE>, indicating
+that timer values are simply a time specified in nanoseconds.
+<P>
+<P>This function is deprecated and should not be used in new applications.
+<P>
+<P>Source: <CODE>/lib/timer.c</CODE>
+<P>
+<P>
+<H3>comedi_get_version_code()</H3>
+
+<P>
+<P><CODE>int comedi_get_version_code(comedi_t *it);</CODE>
+<P>
+<P>The function <CODE>comedi_get_version_code()</CODE> returns the
+version code of the currently running comedi module. The version
+code is of the form 0x01072b, which is the version code for
+version 1.7.43.
+<P>
+<P>This function is of limited usefulness. A typical mis-application
+of this function is to use it to determine if a certain feature is
+supported. If the application needs
+to know of the existence of a particular feature, an existence
+test function should be written and put in the libcomedi source.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<H3>comedi_loglevel()</H3>
+
+<P>
+<P><CODE>int comedi_loglevel(int loglevel);</CODE>
+<P>
+<P>This function affects the output of debugging and error messages
+from libcomedi. By increasing the loglevel, additional debugging
+information will be printed. This function returns the previous
+loglevel. Error messages and debugging are printed to the
+stream <CODE>stderr</CODE>. The loglevel can also be affected by the
+environment variable COMEDI_LOGLEVEL.
+<P>
+<P>In order to conserve resources, some debugging information is
+disabled when libcomedi is compiled.
+<P>
+<P>The meaning of the loglevels is as follows:
+<P>
+<UL>
+<LI><CODE>COMEDILIB_LOGLEVEL=0</CODE>
+
+Comedilib prints nothing.
+</LI>
+<LI><CODE>COMEDILIB_LOGLEVEL=1</CODE> (default)
+
+Comedilib only prints error messages when there is a
+self-consistency error (i.e., internal bug).
+</LI>
+<LI><CODE>COMEDILIB_LOGLEVEL=2</CODE>
+
+Comedilib prints an error message when an invalid
+parameter is passed to comedilib.
+</LI>
+<LI><CODE>COMEDILIB_LOGLEVEL=3</CODE>
+
+Comedilib prints an error message whenever an error is generated
+in the comedilib library or is generated in the C library when
+called by comedilib.
+</LI>
+<LI><CODE>COMEDILIB_LOGLEVEL=4</CODE>
+
+Comedilib prints a lot of debugging messages.
+</LI>
+</UL>
+<P>Bugs: Libcomedi doesn't currently have much debugging information.
+<P>Source: <CODE>/lib/error.c</CODE>
+<P>
+<P>
+<H3>comedi_open()</H3>
+
+<P>
+<P><CODE>comedi_t *comedi_open(char *filename);</CODE>
+<P>Opens a comedi device specified by the filename <CODE>filename</CODE>.
+Returns NULL on error. On sucess, it returns a handle that is
+given as a parameter to other libcomedi functions.
+<P>
+<P>You are not supposed to have access to the internals of the
+<CODE>comedi_t</CODE> structure.
+<P>Bugs: Not strictly identical to <CODE>fopen</CODE>
+<P>Source: <CODE>/lib/comedi.c</CODE>
+<P>
+<P>
+<P>
+<H3><A NAME="comedi_perror"></A> comedi_perror()</H3>
+
+<P>
+<P><CODE>void comedi_perror(const char *s);</CODE>
+<P>When a comedilib function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<CODE>
+<A HREF="#comedi_errno">comedi_errno()</A></CODE>.
+This error number can be
+converted to a human-readable form by the functions
+<CODE>comedi_perror()</CODE>
+and <CODE>
+<A HREF="#comedi_strerror">comedi_strerror()</A></CODE>.
+<P>These functions are intended to mimic the behavior of the
+standard C library functions <CODE>perror()</CODE>,
+<CODE>strerror</CODE>, and <CODE>errno()</CODE>. In particular,
+comedilib functions sometimes return an error that is generated
+inside the C library; the comedi error message in this case
+is the same as the C library.
+<P>The function <CODE>comedi_perror()</CODE> prints an error
+message to stderr. The error message consists of the
+argument string, a colon, a space, a description of the error
+condition, and a new line.
+<P>Bugs: Does not support internationalization.
+<P>Source: <CODE>/lib/error.c</CODE>
+<P>
+<P>
+<P>
+<H3><A NAME="comedi_strerror"></A> comedi_strerror()</H3>
+
+<P>
+<P><CODE>*comedi_strerror(int errnum);</CODE>
+<P>When a comedilib function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<CODE>
+<A HREF="#comedi_errno">comedi_errno()</A></CODE>. This error number can be
+converted to a human-readable form by the functions
+<CODE>
+<A HREF="#comedi_perror">comedi_perror()</A></CODE>
+and <CODE>comedi_strerror()</CODE>.
+<P>These functions are intended to mimic the behavior of the
+standard C library functions <CODE>perror()</CODE>,
+<CODE>strerror</CODE>, and <CODE>errno()</CODE>. In particular,
+comedilib functions sometimes return an error that is generated
+inside the C library; the comedi error message in this case
+is the same as the C library.
+<P>The function <CODE>comedi_strerror()</CODE> returns a pointer to a
+character string
+describing the comedilib error <CODE>errnum</CODE>. The persistence
+of the returned pointer is undefined, and should not be trusted
+after the next libcomedi call. An unrecognized error number will
+return a pointer to the string "undefined error", or similar.
+<P>Bugs: Does not support internationalization.
+<P>Source: <CODE>/lib/error.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_sv_init()</H3>
+
+<P>
+<P><CODE>int comedi_sv_init(comedi_sv_t *sv,comedi_t *dev,unsigned int subd,
+unsigned int chan);</CODE>
+<P>
+<P><CODE>comedi_sv_init</CODE> initializes the slow varying comedi structure
+<CODE>sv</CODE> of the device <CODE>dev</CODE>, the subdevice <CODE>subd</CODE> (analog input) and
+the channel <CODE>chan</CODE>.
+The slow varying comedi structure <CODE>sv</CODE> of type <CODE>
+<A HREF="#comedi_sv_t">comedi_sv_t</A></CODE>
+specifies the signal measurement. The default number of averaged
+samples is 100. Returns zero on success, -1 on error.
+<P>Bugs: comedi_sv_* was very poorly designed.
+<P>Source: <CODE>/lib/sv.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_sv_update()</H3>
+
+<P>
+<P><CODE>int comedi_sv_update(comedi_sv_t *sv);</CODE>
+<P>The function <CODE>comedi_sv_update</CODE> updates the slow varying comedi structure
+<CODE>sv</CODE>.
+Returns zero on success, -1 on error.
+<P>Source: <CODE>/lib/sv.c</CODE>
+<P>
+<P>
+<P>
+<H3>int comedi_sv_measure()</H3>
+
+<P>
+<P><CODE>int comedi_sv_measure(comedi_sv_t *it,double *data);</CODE>
+<P><CODE>comedi_sv_measure</CODE> measures the slow variing signal. The measurement
+is specified by the slow varying comedi structure <CODE>sv</CODE>, the result is
+stored in <CODE>data</CODE>.
+On success returns the number of samples, -1 on error.
+<P>Source: <CODE>/lib/sv.c</CODE>
+<P>
+<P>
+<P>
+<H3><A NAME="comedi_to_phys"></A> comedi_to_phys()</H3>
+
+<P>
+<P><CODE>double comedi_to_phys(lsampl_t data, comedi_range *rng,
+lsampl_t maxdata);</CODE>
+<P>Converts data given in sample values (lsampl_t, between 0 and
+maxdata) into physical units (double). The parameter <CODE>rng</CODE>
+represents the conversion information to use, and the parameter
+<CODE>maxdata</CODE> represents the maximum possible data value for the
+channel that the data was read.
+<P>Source: <CODE>/lib/range.c</CODE>
+<P>
+<P>
+<P>
+<H3>comedi_trigger() <I>(deprecated)</I></H3>
+
+<P>
+<P><CODE>int comedi_trigger(comedi_t *it,comedi_trig *trig);</CODE>
+<P>The function <CODE>comedi_trigger</CODE> instructs comedi to
+perform the command specified by the
+<A HREF="#comedi_trig_struct">trigger structure</A> <CODE>trig</CODE>. Results depend on
+the particular command being issued. If there is an
+error, -1 is returned.
+<P>Lifetime: removal at 1.0.
+<P>Source: <CODE>/lib/comedi.c</CODE>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<H3>comedi_get_timer()</H3>
+
+<P>
+<P>
+<BLOCKQUOTE><CODE>
+<PRE>
+int comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,unsigned int *trigvar,
+ double *actual_freq);
+</PRE>
+</CODE></BLOCKQUOTE>
+<P>
+<P>
+<P>
+<P>
+<HR>
+Next
+Previous
+<A HREF="comedilib_reference.html#toc1">Contents</A>
+</BODY>
+</HTML>
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+ <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
+ <TITLE>Comedi Documentation: Reference Comedilib-0.7.9: types</TITLE>
+ <LINK HREF="comedilib_reference-3.html" REL=next>
+ <LINK HREF="comedilib_reference-1.html" REL=previous>
+ <LINK HREF="comedilib_reference.html#toc2" REL=contents>
+</HEAD>
+<BODY>
+<A HREF="comedilib_reference-3.html">Next</A>
+<A HREF="comedilib_reference-1.html">Previous</A>
+<A HREF="comedilib_reference.html#toc2">Contents</A>
+<HR>
+<H2><A NAME="s2">2. Reference Comedilib-0.7.9: types</A></H2>
+
+<P>
+<H2><A NAME="ss2.1">2.1 sampl_t</A>
+</H2>
+
+<P>defined in <CODE>comedi.h</CODE>
+correspond to <CODE>unsigned int</CODE>
+type of the sample data
+<P>
+<P>
+<H2><A NAME="comedi_sv_t"></A> <A NAME="ss2.2">2.2 comedi_sv_t</A>
+</H2>
+
+<P>defined in <CODE>comedilib.h</CODE>
+correspond to <CODE>
+<A HREF="comedilib_reference-3.html#comedi_sv_struct">comedi_sv_struct</A></CODE>
+<P>
+<P>
+<HR>
+<A HREF="comedilib_reference-3.html">Next</A>
+<A HREF="comedilib_reference-1.html">Previous</A>
+<A HREF="comedilib_reference.html#toc2">Contents</A>
+</BODY>
+</HTML>
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+ <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
+ <TITLE>Comedi Documentation: Reference Comedilib-0.7.9: structures</TITLE>
+ <LINK HREF="comedilib_reference-4.html" REL=next>
+ <LINK HREF="comedilib_reference-2.html" REL=previous>
+ <LINK HREF="comedilib_reference.html#toc3" REL=contents>
+</HEAD>
+<BODY>
+<A HREF="comedilib_reference-4.html">Next</A>
+<A HREF="comedilib_reference-2.html">Previous</A>
+<A HREF="comedilib_reference.html#toc3">Contents</A>
+<HR>
+<H2><A NAME="s3">3. Reference Comedilib-0.7.9: structures</A></H2>
+
+<P>
+<P>
+<H2><A NAME="comedi_trig_struct"></A> <A NAME="ss3.1">3.1 comedi_trig_struct</A>
+</H2>
+
+<P>
+<P>
+<BLOCKQUOTE><CODE>
+<PRE>
+struct comedi_trig_struct{
+ unsigned int subdev; /* subdevice */
+ unsigned int mode; /* mode */
+ unsigned int flags;
+ unsigned int n_chan; /* number of channels */
+ unsigned int *chanlist; /* channel/range list */
+ sampl_t *data; /* data list, size depends on subd flags */
+ unsigned int n; /* number of scans */
+ unsigned int trigsrc;
+ unsigned int trigvar;
+ unsigned int trigvar1;
+ unsigned int data_len;
+ unsigned int unused[3];
+}
+</PRE>
+</CODE></BLOCKQUOTE>
+<P>
+<P>
+<H2><A NAME="comedi_sv_struct"></A> <A NAME="ss3.2">3.2 comedi_sv_struct</A>
+</H2>
+
+<P>
+<BLOCKQUOTE><CODE>
+<PRE>
+struct comedi_sv_struct{
+ comedi_t *dev;
+ unsigned int subdevice;
+ unsigned int chan;
+
+ /* range policy */
+ int range;
+ int aref;
+
+ /* number of measurements to average (for ai) */
+ int n;
+
+ lsampl_t maxdata;
+}
+</PRE>
+</CODE></BLOCKQUOTE>
+<P>
+<HR>
+<A HREF="comedilib_reference-4.html">Next</A>
+<A HREF="comedilib_reference-2.html">Previous</A>
+<A HREF="comedilib_reference.html#toc3">Contents</A>
+</BODY>
+</HTML>
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+ <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
+ <TITLE>Comedi Documentation: Reference Comedilib-0.7.9: functions</TITLE>
+ <LINK HREF="comedilib_reference-3.html" REL=previous>
+ <LINK HREF="comedilib_reference.html#toc4" REL=contents>
+</HEAD>
+<BODY>
+Next
+<A HREF="comedilib_reference-3.html">Previous</A>
+<A HREF="comedilib_reference.html#toc4">Contents</A>
+<HR>
+<H2><A NAME="s4">4. Reference Comedilib-0.7.9: functions</A></H2>
+
+<P>
+<P>
+<H2><A NAME="ss4.1">4.1 comedi_close()</A>
+</H2>
+
+<P>
+<P><CODE>void comedi_close(comedi_t *it);</CODE>
+<P>Closes a device previously opened by comedi_open().
+<P>Source: <CODE>/lib/comedi.c</CODE>
+<P>
+<H2><A NAME="ss4.2">4.2 comedi_data_read()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
+unsigned int range,unsigned int aref,lsampl_t *data);</CODE>
+<P>Reads a single sample on the channel that
+is specified by the comedi device <CODE>it</CODE>, the
+subdevice <CODE>subd</CODE>, and the channel <CODE>chan</CODE>.
+For the operation,
+the device is configured to use range specification
+<CODE>range</CODE> and (if appropriate) analog reference type
+<CODE>aref</CODE>. Analog reference types that are not supported
+by the device are silently ignored.
+<P><CODE>comedi_data_read()</CODE> reads one data value from
+the specified channel and places the
+data value that is read in the location pointed to by
+<CODE>data</CODE>.
+<P>On sucess, <CODE>comedi_data_read()</CODE> returns 0. If there is an error, -1 is
+returned.
+<P>Valid analog reference numbers are:
+<P>
+<UL>
+<LI>AREF_GROUND Reference to analog ground</LI>
+<LI>AREF_COMMON Reference to analog common</LI>
+<LI>AREF_DIFF Differential reference</LI>
+<LI>AREF_OTHER Board-specific meaning</LI>
+</UL>
+<P>Valid data values used by these function is an unsigned integer
+less than or equal to <CODE>maxdata</CODE>, which is channel-dependent.
+Conversion of these data value to physical units can be performed
+by <CODE>
+<A HREF="#comedi_to_phys">comedi_to_phys()</A></CODE>.
+<P>Source: <CODE>/lib/data.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.3">4.3 comedi_data_write()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
+unsigned int range,unsigned int aref,lsampl_t data);</CODE>
+<P>Writes a single sample on the channel that
+is specified by the comedi device <CODE>it</CODE>, the
+subdevice <CODE>subd</CODE>, and the channel <CODE>chan</CODE>.
+For the operation,
+the device is configured to use range specification
+<CODE>range</CODE> and (if appropriate) analog reference type
+<CODE>aref</CODE>. Analog reference types that are not supported
+by the device are silently ignored.
+<P><CODE>comedi_data_write()</CODE> writes the data value
+specified by the argument <CODE>data</CODE> to
+the specified channel.
+<P>On sucess, <CODE>comedi_data_write()</CODE> returns 0. If there is an error, -1 is
+returned.
+<P>Valid analog reference numbers are:
+<P>
+<UL>
+<LI>AREF_GROUND Reference to analog ground</LI>
+<LI>AREF_COMMON Reference to analog common</LI>
+<LI>AREF_DIFF Differential reference</LI>
+<LI>AREF_OTHER Board-specific meaning</LI>
+</UL>
+<P>Valid data values used by these functions is an unsigned integer
+less than or equal to <CODE>maxdata</CODE>, which is channel-dependent.
+Conversion of physical units to these data value can be performed
+by <CODE>
+<A HREF="#comedi_from_phys">comedi_from_phys()</A></CODE>.
+<P>Source: <CODE>/lib/data.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.4">4.4 comedi_dio_bitfield();</A>
+</H2>
+
+<P>int comedi_dio_bitfield(comedi_t *it,unsigned int subd,unsigned int write_mask,
+unsigned int *bits);
+<P>Source: <CODE>/lib/dio.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.5">4.5 comedi_dio_config()</A>
+</H2>
+
+<P><CODE>int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned int chan,unsigned int dir);</CODE>
+<P>The function <CODE>comedi_dio_config</CODE> configures the direction <CODE>dir</CODE> of
+channel <CODE>chan</CODE> belonging to the configurable digital input/output subdevice
+<CODE>subd</CODE> of the device <CODE>it</CODE>. Returns -1 on failure.
+<P>
+<P>Valid directions are:
+<UL>
+<LI> COMEDI_INPUT</LI>
+<LI> COMEDI_OUTPUT</LI>
+</UL>
+<P>Source: <CODE>/lib/dio.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.6">4.6 comedi_dio_read()</A>
+</H2>
+
+<P><CODE>int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan,unsigned int *bit);</CODE>
+<P>The function reads the status of channel <CODE>chan</CODE> belonging to the digital
+input subdevice <CODE>subd</CODE> of device <CODE>it</CODE>. The result, 0 or 1, is stored
+in bit. Returns -1 on failure.
+<P>Source: <CODE>/lib/dio.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.7">4.7 comedi_dio_write()</A>
+</H2>
+
+<P><CODE>int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,unsigned int bit);</CODE>
+<P>The function writes the value of <CODE>bit</CODE>, 0 or 1, in channel <CODE>chan</CODE>,
+belonging to the digital output device <CODE>subd</CODE> of device <CODE>it</CODE>. Returns
+-1 on failure.
+<P>Source: <CODE>/lib/dio.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.8">4.8 comedi_fileno()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_fileno(comedi_t *it);</CODE>
+<P>The function <CODE>comedi_fileno</CODE>
+returns the integer descriptor for the handle <CODE>it</CODE>. If
+<CODE>it</CODE> is an invalid <CODE>comedi_t</CODE> pointer, the function
+returns -1 and sets the appropriate comedilib error value.
+<P>Source: <CODE>/lib/comedi.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.9">4.9 comedi_find_range()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_find_range(comedi_t *it, unsigned int subdevice, unsigned
+int chan, unsigned int unit, double min, double max);</CODE>
+<P>The function <CODE>comedi_find_range</CODE> tries to
+locate the optimal (smallest) range of a channel <CODE>chan</CODE> belonging to a
+<CODE>subdevice</CODE> of the comedi device <CODE>it</CODE>, which includes the data
+range between <CODE>min</CODE> and <CODE>max</CODE> in <CODE>units</CODE> with highest
+precision. If it finds a matching range,
+it returns its index. If no matching range is available, it returns -1.
+<P>Valid units are:
+<P>
+<UL>
+<LI>UNIT_volt </LI>
+<LI>UNIT_mA</LI>
+<LI>UNIT_none</LI>
+</UL>
+<P>Source: <CODE>/lib/range.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="comedi_errno"></A> <A NAME="ss4.10">4.10 comedi_errno()</A>
+</H2>
+
+<P><CODE>int comedi_errno(void);</CODE>
+<P>
+<P>When a comedilib function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<CODE>comedi_errno()</CODE>. This error number can be
+converted to a human-readable form by the functions
+<CODE>
+<A HREF="#comedi_perror">comedi_perror()</A></CODE>
+and <CODE>
+<A HREF="#comedi_strerror">comedi_strerror()</A></CODE>.
+<P>These functions are intended to mimic the behavior of the
+standard C library functions <CODE>perror()</CODE>,
+<CODE>strerror</CODE>, and <CODE>errno()</CODE>. In particular,
+comedilib functions sometimes return an error that is generated
+inside the C library; the comedi error message in this case
+is the same as the C library.
+<P>The function <CODE>comedi_errno()</CODE>
+returns an integer describing the most recent comedilib error. This
+integer may be used as the <CODE>errnum</CODE> parameter for
+<CODE>
+<A HREF="#comedi_strerror">comedi_strerror()</A></CODE>.
+<P>Source: <CODE>/lib/error.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.11">4.11 comedi_find_subdevice_by_type()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int
+start_subdevice);</CODE>
+<P>The function <CODE>comedi_find_subdevice_by_type</CODE> tries to
+locate a subdevice belonging to comedi device <CODE>it</CODE>,
+having type <CODE>type</CODE>, starting with the subdevice
+<CODE>start_subdevice</CODE>. If it finds the requested subdevice,
+it returns its index. If it does not locate the requested
+subdevice, it returns -1 and sets the comedi error number to
+"subdevice not found". If there is an error, the function
+returns -1 and sets the appropriate error.
+<P>For subdevice types, see the manual page for the function
+<CODE>
+<A HREF="#comedi_get_subdevice_type">comedi_get_subdevice_type()</A></CODE>.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="comedi_from_phys"></A> <A NAME="ss4.12">4.12 comedi_from_phys()</A>
+</H2>
+
+<P>
+<P><CODE>lsampl_t comedi_from_phys(double data, comedi_range *rng, lsampl_t maxdata);</CODE>
+<P>Converts data given in physical units (double) into sample values (lsampl_t, between 0 and maxdata).
+The parameter <CODE>rng</CODE> represents the conversion information to use, and the parameter <CODE>maxdata</CODE> represents
+the maximum possible data value for the channel that the data will be written to.
+<P>Source: <CODE>/lib/range.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.13">4.13 comedi_get_board_name()</A>
+</H2>
+
+<P>
+<P><CODE>char *comedi_get_board_name(comedi_t *it);</CODE>
+<P>The function <CODE>comedi_get_board_name</CODE> returns a pointer
+to a string containing the name of the device. This pointer is
+valid until the comedi descriptor <CODE>it</CODE> is closed. This
+function returns NULL if there is an error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.14">4.14 comedi_get_driver_name()</A>
+</H2>
+
+<P>
+<P><CODE>char *comedi_get_driver_name(comedi_t *it);</CODE>
+<P>The function <CODE>comedi_get_driver_name</CODE> returns a pointer
+to a string containing the name of the driver being used by comedi
+for the comedi device represented by <CODE>it</CODE>. This pointer is
+valid until the comedi descriptor <CODE>it</CODE> is closed. This
+function returns NULL if there is an error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.15">4.15 comedi_get_maxdata()</A>
+</H2>
+
+<P>
+<P><CODE>lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,unsigned int
+chan);</CODE>
+<P>The function <CODE>comedi_get_maxdata()</CODE> returns the maximum
+valid data value for channel <CODE>chan</CODE> of subdevice
+<CODE>subdevice</CODE> belonging to the comedi device <CODE>it</CODE>
+This function returns 0 on error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.16">4.16 comedi_get_n_channels()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_get_n_channels(comedi_t *it,unsigned int subdevice);</CODE>
+<P>The function <CODE>comedi_get_n_channels()</CODE> returns the number
+of channels of the subdevice belonging to the comedi device <CODE>it</CODE>
+and having index <CODE>subdevice</CODE>. This function returns -1 on error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.17">4.17 comedi_get_n_ranges()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice, unsigned int
+chan);</CODE>
+<P>The function <CODE>comedi_get_n_ranges()</CODE> returns the number
+of ranges of the channel <CODE>chan</CODE> belonging to the <CODE>subdevice</CODE>
+of the comedi device <CODE>it</CODE>. This function returns -1 on error.
+<P>Source: <CODE>/lib/range.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.18">4.18 comedi_get_n_subdevices()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_get_n_subdevices(comedi_t *it);</CODE>
+<P>The function <CODE>comedi_get_n_subdevices</CODE> returns the
+number of subdevices associated with the comedi descriptor
+<CODE>it</CODE>, or -1 if there is an error.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.19">4.19 comedi_get_range()</A>
+</H2>
+
+<P>
+<P><CODE>comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,unsigned int chan,unsigned int
+range);</CODE>
+<P>The function <CODE>comedi_get_range</CODE> returns a pointer to a
+comedi_range structure that contains information that can be used to
+convert sample values to or from physical units. The pointer is valid
+until the comedi device <CODE>it</CODE> is closed. If there is an
+error, NULL is returned.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.20">4.20 comedi_get_rangetype()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,unsigned int
+chan);</CODE>
+<P>The function <CODE>comedi_get_rangetype()</CODE> returns an integer
+that represents the number of range specifications available for a
+particular channel <CODE>chan</CODE> of the subdevice <CODE>subdevice</CODE>, as well as a conversion table to convert sample
+values to/from physical units.
+<P>The macro
+<CODE>RANGE_LENGTH(rangetype)</CODE>
+can be used to determine the number of range specifications for a given
+range type.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<H2><A NAME="comedi_get_subdevice_type"></A> <A NAME="ss4.21">4.21 comedi_get_subdevice_type()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice);</CODE>
+<P>The function <CODE>comedi_get_subdevice_type()</CODE> returns an
+integer describing the type of subdevice that belongs to the comedi
+device <CODE>it</CODE> and has the index <CODE>subdevice</CODE>. The
+function returns -1 is there is an error.
+<P>Valid subdevice types are:
+<P>
+<UL>
+<LI><CODE>COMEDI_SUBD_UNUSED</CODE>
+Subdevice has no functionality, i.e., a place-holder.</LI>
+<LI><CODE>COMEDI_SUBD_AI</CODE> Analog input</LI>
+<LI><CODE>COMEDI_SUBD_AO</CODE> Analog output</LI>
+<LI><CODE>COMEDI_SUBD_DI</CODE> Digital input</LI>
+<LI><CODE>COMEDI_SUBD_DO</CODE> Digital output</LI>
+<LI><CODE>COMEDI_SUBD_DIO</CODE>
+Digital input/output. Channels are configurable as to whether they
+are inputs or outputs.</LI>
+<LI><CODE>COMEDI_SUBD_COUNTER</CODE> Counter</LI>
+<LI><CODE>COMEDI_SUBD_TIMER</CODE> Timer</LI>
+<LI><CODE>COMEDI_SUBD_MEMORY</CODE>
+Memory, e.g., EEPROM or dual-ported RAM</LI>
+<LI><CODE>COMEDI_SUBD_CALIB</CODE>
+Calibration DACs</LI>
+<LI><CODE>COMEDI_SUBD_PROC</CODE>
+Processor or DSP</LI>
+</UL>
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.22">4.22 comedi_get_timer()</A>
+</H2>
+
+<P>
+<P>
+<BLOCKQUOTE><CODE>
+<PRE>
+int comedi_get_timer(comedi_t *it,unsigned int subdev, double freq,unsigned int *trigvar,
+ double *actual_freq);
+</PRE>
+</CODE></BLOCKQUOTE>
+<P><CODE>comedi_get_timer</CODE> returns the type of the timer of the subdevice
+<CODE>subdev</CODE> of the device <CODE>it</CODE> ,
+<P>Supported timers are:
+<P>
+<UL>
+<LI>NULL</LI>
+<LI>dt282x_timer</LI>
+<LI>dt2814_timer</LI>
+<LI>atmio_timer</LI>
+<LI>acl8112_timer</LI>
+<LI>nanosec_timer</LI>
+</UL>
+<P>Source: <CODE>/lib/timer.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.23">4.23 comedi_get_version_code()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_get_version_code(comedi_t *it);</CODE>
+<P>The function <CODE>comedi_get_version_code()</CODE> returns the
+version code of the currently running comedi module. The version
+code is of the form 0x01072b, which is the version code for
+version 1.7.43.
+<P>Source: <CODE>/lib/get.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.24">4.24 comedi_loglevel()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_loglevel(int loglevel);</CODE>
+<P>This function affects the output of debugging and error messages
+from comedlib. By increasing the loglevel, additional debugging
+information will be printed. This function returns the previous
+loglevel. Some debugging information will only be printed if
+comedilib was compiled with this debugging information included.
+The loglevel can also be affected by the environment
+variable COMEDI_LOGLEVEL. The meaning of the loglevels is as
+follows:
+<P>COMEDILIB_LOGLEVEL=0
+<P>Comedilib prints nothing.
+<P>COMEDILIB_LOGLEVEL=1 (default)
+<P>Comedilib only prints error messages when there is a
+self-consistency error.
+<P>COMEDILIB_LOGLEVEL=2
+<P>Comedilib prints an error message whenever an invalid
+parameter is passed to comedilib.
+<P>COMEDILIB_LOGLEVEL=3
+<P>Comedilib prints an error message whenever an error is generated
+in the comedilib library or is generated in the C library when
+called by comedilib.
+<P>COMEDILIB_LOGLEVEL=4
+<P>Comedilib prints a lot of debugging messages.
+<P>
+<P>Source: <CODE>/lib/error.c</CODE>
+<P>
+<P>
+<H2><A NAME="ss4.25">4.25 comedi_open()</A>
+</H2>
+
+<P>
+<P><CODE>comedi_t *comedi_open(char *fn);</CODE>
+<P>Opens a comedi device specified by the filename fn. Returns NULL
+on error. Returns a handle that is given as a parameter to other
+comedilib functions.
+<P>You are not supposed to have access to the structure comedi_t.
+<P>Source: <CODE>/lib/comedi.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="comedi_perror"></A> <A NAME="ss4.26">4.26 comedi_perror()</A>
+</H2>
+
+<P>
+<P><CODE>void comedi_perror(const char *s);</CODE>
+<P>When a comedilib function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<CODE>
+<A HREF="#comedi_errno">comedi_errno()</A></CODE>.
+This error number can be
+converted to a human-readable form by the functions
+<CODE>comedi_perror()</CODE>
+and <CODE>
+<A HREF="#comedi_strerror">comedi_strerror()</A></CODE>.
+<P>These functions are intended to mimic the behavior of the
+standard C library functions <CODE>perror()</CODE>,
+<CODE>strerror</CODE>, and <CODE>errno()</CODE>. In particular,
+comedilib functions sometimes return an error that is generated
+inside the C library; the comedi error message in this case
+is the same as the C library.
+<P>The function <CODE>comedi_perror()</CODE> prints an error
+message to stderr. The error message consists of the
+argument string, a colon, a space, a description of the error
+condition, and a new line.
+<P>Source: <CODE>/lib/error.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="comedi_strerror"></A> <A NAME="ss4.27">4.27 comedi_strerror()</A>
+</H2>
+
+<P>
+<P><CODE>*comedi_strerror(int errnum);</CODE>
+<P>When a comedilib function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<CODE>
+<A HREF="#comedi_errno">comedi_errno()</A></CODE>. This error number can be
+converted to a human-readable form by the functions
+<CODE>
+<A HREF="#comedi_perror">comedi_perror()</A></CODE>
+and <CODE>comedi_strerror()</CODE>.
+<P>These functions are intended to mimic the behavior of the
+standard C library functions <CODE>perror()</CODE>,
+<CODE>strerror</CODE>, and <CODE>errno()</CODE>. In particular,
+comedilib functions sometimes return an error that is generated
+inside the C library; the comedi error message in this case
+is the same as the C library.
+<P>The function <CODE>comedi_strerror()</CODE> returns a pointer to a
+character string
+describing the comedilib error <CODE>errnum</CODE>. The persistence
+of the returned pointer is undefined, and should not be trusted
+after the next comedilib call. An unrecognized error number will
+return a pointer to the string "undefined error", or similar.
+<P>Valid error strings are:
+<P>
+<UL>
+<LI><CODE>"No error"</CODE></LI>
+<LI><CODE>"Unknown error</CODE></LI>
+<LI><CODE>"Bad comedi_t structure"</CODE></LI>
+<LI><CODE>"Invalid subdevice"</CODE></LI>
+<LI><CODE>"Invalid channel"</CODE></LI>
+</UL>
+<P>Source: <CODE>/lib/error.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.28">4.28 comedi_sv_init()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_sv_init(comedi_sv_t *sv,comedi_t *dev,unsigned int subd,
+unsigned int chan);</CODE>
+<P>The special functions <CODE>comedi_sv_*()</CODE> are designed to
+make it easy to accurately measure slowly varying analog inputs.
+A slowly varying input is one that is effectively constant over the course
+of approximately 100 A/D conversions. However, since these
+conversions can sometimes be pre-empted by scheduling, for most
+purposes, a slowly varying signal should be effectively constant
+for greater than 20 ms (the default Linux timeslice).
+<P>By averaging many A/D conversions of a relatively constant
+signal, it is possible to get a better measurement of the signal
+than a single A/D conversion. In general, the uncertainty of the
+measurement decreases as the square root of the number of samples.
+This is limited by the rate that which the signal varies, and
+ultimately by the spurious free dynamic range of the A/D converter.
+<P><CODE>comedi_sv_init</CODE> initializes the slow varying comedi structure
+<CODE>sv</CODE> of the device <CODE>dev</CODE>, the subdevice <CODE>subd</CODE> (analog input) and
+the channel <CODE>chan</CODE>.
+The slow varying comedi structure <CODE>sv</CODE> of type <CODE>
+<A HREF="comedilib_reference-2.html#comedi_sv_t">comedi_sv_t</A></CODE>
+specifies the signal measurement. Default number of averaged samples is 100.
+Returns zero on success, -1 on error.
+<P>Source: <CODE>/lib/sv.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.29">4.29 comedi_sv_update()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_sv_update(comedi_sv_t *sv);</CODE>
+<P><CODE>comedi_sv_update</CODE> updates the slow varying comedi structure
+<CODE>sv</CODE>.
+Returns zero on success, -1 on error.
+<P>Source: <CODE>/lib/sv.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.30">4.30 int comedi_sv_measure()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_sv_measure(comedi_sv_t *it,double *data);</CODE>
+<P><CODE>comedi_sv_measure</CODE> measures the slow variing signal. The measurement
+is specified by the slow varying comedi structure <CODE>sv</CODE>, the result is
+stored in <CODE>data</CODE>.
+On success returns the number of samples, -1 on error.
+<P>Source: <CODE>/lib/sv.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="comedi_to_phys"></A> <A NAME="ss4.31">4.31 comedi_to_phys()</A>
+</H2>
+
+<P>
+<P><CODE>double comedi_to_phys(lsampl_t data, comedi_range *rng, lsampl_t maxdata);</CODE>
+<P>Converts data given in sample values (lsampl_t, between 0 and maxdata) into physical units (double).
+The parameter <CODE>rng</CODE> represents the conversion information to use, and the parameter <CODE>maxdata</CODE> represents
+the maximum possible data value for the channel that the data was read.
+<P>Source: <CODE>/lib/range.c</CODE>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.32">4.32 comedi_trigger()</A>
+</H2>
+
+<P>
+<P><CODE>int comedi_trigger(comedi_t *it,comedi_trig *trig);</CODE>
+<P>The function <CODE>comedi_trigger()</CODE> instructs comedi to
+perform the command specified by the
+<A HREF="comedilib_reference-3.html#comedi_trig_struct">trigger structure</A>
+<CODE>trig</CODE>. Results depend on the particular command
+being issued. If there is an error, -1 is returned.
+<P>Complete information about comedi commands is given in the
+manual page comedi(8).
+<P>Source: <CODE>/lib/comedi.c</CODE>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<P>
+<H2><A NAME="ss4.33">4.33 comedi_get_timer()</A>
+</H2>
+
+<P>
+<P>
+<BLOCKQUOTE><CODE>
+<PRE>
+int comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,unsigned int *trigvar,
+ double *actual_freq);
+</PRE>
+</CODE></BLOCKQUOTE>
+<P>
+<P>
+<P>
+<P>
+<HR>
+Next
+<A HREF="comedilib_reference-3.html">Previous</A>
+<A HREF="comedilib_reference.html#toc4">Contents</A>
+</BODY>
+</HTML>
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+ <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
+ <TITLE>Comedi Documentation</TITLE>
+ <LINK HREF="comedilib_reference-1.html" REL=next>
+
+
+</HEAD>
+<BODY>
+<A HREF="comedilib_reference-1.html">Next</A>
+Previous
+Contents
+<HR>
+<H1>Comedi Documentation</H1>
+
+<H2>David Schleef, <CODE>ds@stm.lbl.gov</CODE> </H2>
+<P>
+<H2><A NAME="toc1">1.</A> <A HREF="comedilib_reference-1.html">Libcomedi Reference</A></H2>
+
+<UL>
+<LI><A HREF="comedilib_reference-1.html#ss1.1">1.1 Constants and Macros</A>
+<LI><A HREF="comedilib_reference-1.html#ss1.2">1.2 Data Types and Structures</A>
+<LI><A HREF="comedilib_reference-1.html#ss1.3">1.3 Functions</A>
+</UL>
+<HR>
+<A HREF="comedilib_reference-1.html">Next</A>
+Previous
+Contents
+</BODY>
+</HTML>
--- /dev/null
+<!doctype linuxdoc public "-//LinuxDoc//DTD LinuxDoc 96//EN">
+
+<article>
+<title>Comedi Documentation
+<author>David Schleef, <tt/ds@stm.lbl.gov/
+
+
+
+
+<sect>Libcomedi Reference
+<p>
+
+<sect1>Constants and Macros
+<p>
+
+
+<sect2>RANGE_LENGTH() <it/(deprecated)/
+<p>
+<label id="RANGE_LENGTH">
+
+<tt/RANGE_LENGTH(rangetype)/
+
+<p>
+Rangetype values are library-internal tokens that represent an
+array of range information structures. These numbers are primarily
+used for communication between the kernel and library.
+
+<p>
+The RANGE_LENGTH() macro returns the length of the array that is
+specified by the rangetype token.
+
+<p>
+The RANGE_LENGTH() macro is deprecated, and should not be used in
+new applications. It is scheduled to be removed from the header
+file at version 1.0. Binary compatibility may be broken for version
+1.1.
+
+
+<p>
+<sect1>Data Types and Structures
+
+<p>
+<sect2>comedi_t
+<label id="comedi_t">
+
+<p>
+The data type <tt/comedi_t/ is used to represent an open Comedi
+device. A valid <tt/comedi_t/ pointer is returned by a successful
+call to <tt/comedi_open()/, and should be used for subsequent
+access to the device.
+It is a transparent type, and pointers to type <tt/comedi_t/
+should not be dereferenced.
+
+
+<p>
+<sect2>sampl_t
+<label id="sampl_t">
+
+<p>
+The data type <tt/sampl_t/ is one of the generic types used to represent
+data values in libcomedi. It is used in a few places where a shorter
+data type is useful, but is limited to 16 bits on the i386 architecture.
+
+
+<p>
+<sect2>lsampl_t
+<label id="lsampl_t">
+
+<p>
+The data type <tt/lsampl_t/ is one of the generic types used to represent
+data values in libcomedi. It is currently defined to be <tt/unsigned int/.
+
+
+
+
+<p>
+<sect2>comedi_trig_struct <it/(deprecated)/
+<label id="comedi_trig_struct">
+<p>
+
+The <tt/comedi_trig/ structure
+
+<tscreen><verb>
+struct comedi_trig_struct{
+ unsigned int subdev; /* subdevice */
+ unsigned int mode; /* mode */
+ unsigned int flags;
+ unsigned int n_chan; /* number of channels */
+ unsigned int *chanlist; /* channel/range list */
+ sampl_t *data; /* data list, size depends on subd flags */
+ unsigned int n; /* number of scans */
+ unsigned int trigsrc;
+ unsigned int trigvar;
+ unsigned int trigvar1;
+ unsigned int data_len;
+ unsigned int unused[3];
+}
+</verb></tscreen>
+
+The <tt/comedi_trig/ structure is a control structure used by the
+COMEDI_TRIG ioctl, an older method of communicating
+instructions to the driver and hardware. Use of Comedi triggers is
+deprecated, and should not be used in new applications.
+
+
+<p>
+<sect2>comedi_sv_t
+<label id="comedi_sv_t">
+<p>
+
+<tscreen><verb>
+struct comedi_sv_struct{
+ comedi_t *dev;
+ unsigned int subdevice;
+ unsigned int chan;
+
+ /* range policy */
+ int range;
+ int aref;
+
+ /* number of measurements to average (for ai) */
+ int n;
+
+ lsampl_t maxdata;
+}
+</verb></tscreen>
+
+The <tt/comedi_sv_t/ structure is used by the <tt/comedi_sv_*()/
+functions to provide a simple method of accurately measuring
+slowly varying inputs. See the relevant section for more
+details.
+
+
+
+<sect1>Functions
+<p>
+
+<sect2>comedi_close()
+<label id="comedi_close">
+<p>
+
+<tt>void comedi_close(comedi_t *it);</tt>
+
+<p>
+Closes a device previously opened by comedi_open().
+
+<p>
+The return type of this function will change to <tt/int/, in
+order to match <tt/fclose/.
+
+<p>
+Source: <tt>/lib/comedi.c</tt>
+
+
+<sect2>comedi_data_read()
+<label id="comedi_data_read">
+<p>
+
+<tt>int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
+ unsigned int range,unsigned int aref,lsampl_t *data);</tt>
+
+<p>
+Reads a single sample on the channel that
+is specified by the comedi device <tt>it</tt>, the
+subdevice <tt>subd</tt>, and the channel <tt>chan</tt>.
+For the A/D conversion (if appropriate),
+the device is configured to use range specification
+<tt>range</tt> and (if appropriate) analog reference type
+<tt>aref</tt>. Analog reference types that are not supported
+by the device are silently ignored.
+
+<p>
+<tt>comedi_data_read()</tt> reads one data value from
+the specified channel and places the
+data value that is read in the location pointed to by
+<tt>data</tt>.
+
+<p>
+On sucess, <tt>comedi_data_read()</tt> returns 0. If there is an
+error, -1 is returned.
+
+<p>
+Valid analog reference numbers are:
+
+<itemize>
+<item>AREF_GROUND Reference to analog ground
+<item>AREF_COMMON Reference to analog common
+<item>AREF_DIFF Differential reference
+<item>AREF_OTHER Board-specific meaning
+</itemize>
+
+Valid data values returned by these function is an unsigned integer
+less than or equal to <tt>maxdata</tt>, which is channel-dependent.
+Conversion of these data value to physical units can be performed
+by <tt><ref id="comedi_to_phys" name =
+"comedi_to_phys()"></tt>.
+
+Source: <tt>/lib/data.c</tt>
+
+
+<sect2>comedi_data_write()
+<p>
+
+<tt>int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
+ unsigned int range,unsigned int aref,lsampl_t data);</tt>
+
+<p>
+Writes a single sample on the channel that
+is specified by the comedi device <tt/it/, the
+subdevice <tt/subd/, and the channel <tt/chan/.
+For the D/A conversion (if appropriate), the device is
+configured to use range specification
+<tt/range/ and (if appropriate) analog reference type
+<tt/aref/. Analog reference types that are not supported
+by the device are silently ignored.
+
+<tt/comedi_data_write()/ writes the data value
+specified by the argument <tt/data/ to
+the specified channel.
+
+On sucess, <tt>comedi_data_write()</tt> returns 0. If there is an error, -1 is
+returned.
+
+Valid analog reference numbers are:
+
+<itemize>
+<item>AREF_GROUND Reference to analog ground
+<item>AREF_COMMON Reference to analog common
+<item>AREF_DIFF Differential reference
+<item>AREF_OTHER Board-specific meaning
+</itemize>
+
+Valid data values used by these functions is an unsigned integer
+less than or equal to <tt>maxdata</tt>, which is channel-dependent.
+Conversion of physical units to these data value can be performed
+by <tt><ref id="comedi_from_phys" name =
+"comedi_from_phys()"></tt>.
+
+Source: <tt>/lib/data.c</tt>
+
+
+<p>
+<sect2>comedi_dio_bitfield();
+
+<p>
+<tt/int comedi_dio_bitfield(comedi_t *it,unsigned int subd,unsigned
+int write_mask,unsigned int *bits);/
+
+<p>
+The function <tt/comedi_dio_bitfield()/ allows multiple channels to
+be read simultaneously from a digital input or digital I/O device.
+The parameter <tt/write_mask/ and the value pointed to by <tt/bits/
+are interpreted as bit fields, with the least significant bit
+representing channel 0. For each bit in <tt/write_mask/ that is
+set, the cooresponding bit in <tt/*bits/ is written to the digital
+output channel. Each digital input channel is read, and the result
+placed in the approprate bits in <tt/*bits/.
+
+<p>
+The current implementation reads and writes bits using separate
+system calls, which is not ideal. When the kernel driver supports
+simultaneous reading/writing, this will be fixed in the library.
+
+<p>
+It should be noted that it is not possible to access channels
+greater than 31 using this function.
+
+<p>
+Source: <tt>/lib/dio.c</tt>
+
+
+<p>
+<sect2>comedi_dio_config()
+<p>
+<tt/int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned
+int chan,unsigned int dir);/
+
+<p>
+The function <tt/comedi_dio_config/ configures individual channels
+in a digital I/O subdevice to be either input or output, depending
+on the value of parameter <tt/dir/. Depending on the capabilities
+of the hardware device, multiple channels may be affected by
+a single call to <tt/comedi_dio_config/.
+
+
+Valid directions are:
+<itemize>
+<item> COMEDI_INPUT
+<item> COMEDI_OUTPUT
+</itemize>
+
+Source: <tt>/lib/dio.c</tt>
+
+
+<p>
+<sect2>comedi_dio_read()
+<p>
+<tt/int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int
+chan,unsigned int *bit);/
+
+<p>
+The function reads the status of channel <tt/chan/ belonging to the digital
+input subdevice <tt/subd/ of device <tt/it/. The result, 0 or 1, is stored
+in bit. Returns -1 on failure.
+
+<p>
+This function is equivalent to <tt/comedi_data_read(it,subd,chan,0,0,bit)/.
+
+
+Source: <tt>/lib/dio.c</tt>
+
+<p>
+<sect2>comedi_dio_write()
+<p>
+<tt/int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned
+int chan,unsigned int bit);/
+
+<p>
+The function writes the value of <tt/bit/, 0 or 1, to channel <tt/chan/,
+belonging to the digital output device <tt/subd/ of device <tt/it/. Returns
+-1 on failure.
+
+<p>
+Source: <tt>/lib/dio.c</tt>
+
+<p>
+<sect2>comedi_fileno()
+<p>
+
+<tt/int comedi_fileno(comedi_t *it);/
+<p>
+
+The function <tt/comedi_fileno/
+returns the integer descriptor for the handle <tt/it/. It
+is equivalent to the standard function <tt/fileno/. If
+<tt>it</tt> is an invalid <tt>comedi_t</tt> pointer, the function
+returns -1 and sets the appropriate libcomedi error value.
+
+Source: <tt>/lib/comedi.c</tt>
+
+
+<p>
+<sect2>comedi_find_range()
+<p>
+
+<tt/int comedi_find_range(comedi_t *it, unsigned int subdevice, unsigned
+int chan, unsigned int unit, double min, double max);/
+
+<p>
+The function <tt/comedi_find_range/ tries to
+locate the optimal (smallest) range for the channel <tt>chan</tt>
+belonging to a <tt>subdevice</tt> of the comedi device <tt>it</tt>,
+that includes both <tt>min</tt> and <tt>max</tt> in <tt>units</tt>.
+If it finds a matching range, it returns its index. If no
+matching range is available, it returns -1.
+
+<p>
+Valid units are:
+
+<itemize>
+<item>UNIT_volt
+<item>UNIT_mA
+<item>UNIT_none
+</itemize>
+
+Source: <tt>/lib/range.c</tt>
+
+
+<p>
+<sect2>comedi_errno()
+<label id="comedi_errno">
+<p>
+<tt/int comedi_errno(void);/
+
+<p>
+The function <tt>comedi_errno()</tt>
+returns an integer describing the most recent comedilib error. This
+integer may be used as the <tt>errnum</tt> parameter for
+<tt><ref id="comedi_strerror" name ="comedi_strerror()"></tt>.
+
+When a libcomedi function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<tt>comedi_errno()</tt>. This error number can be
+converted to a human-readable form by the functions
+<tt><ref id="comedi_perror" name ="comedi_perror()"></tt>
+ and <tt><ref id="comedi_strerror" name ="comedi_strerror()"></tt>.
+
+These functions are intended to mimic the behavior of the
+standard C library functions <tt>perror()</tt>,
+<tt>strerror</tt>, and <tt>errno()</tt>. In particular,
+libcomedi functions sometimes return an error that is generated
+by the C library; the Comedi error message in this case
+is the same as the C library.
+
+Source: <tt>/lib/error.c</tt>
+
+
+<p>
+<sect2>comedi_find_subdevice_by_type()
+<p>
+
+<tt>int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int
+start_subdevice);</tt>
+
+<p>
+The function <tt>comedi_find_subdevice_by_type</tt> tries to
+locate a subdevice belonging to comedi device <tt>it</tt>,
+having type <tt>type</tt>, starting with the subdevice
+<tt>start_subdevice</tt>. If it finds the requested subdevice,
+it returns its index. If it does not locate the requested
+subdevice, it returns -1 and sets the comedi error number to
+"subdevice not found". If there is an error, the function
+returns -1 and sets the appropriate error.
+
+<p>
+For subdevice types, see the manual page for the function
+<tt><ref id="comedi_get_subdevice_type" name =
+"comedi_get_subdevice_type()"></tt>.
+
+Source: <tt>/lib/get.c</tt>
+
+
+<p>
+<sect2>comedi_from_phys()<label id="comedi_from_phys">
+<p>
+
+<tt/lsampl_t comedi_from_phys(double data, comedi_range *rng,
+lsampl_t maxdata);/
+
+Converts data given in physical units (<tt/data/) into sample values
+(lsampl_t, between 0 and maxdata). The parameter <tt>rng</tt>
+represents the conversion information to use, and the parameter
+<tt>maxdata</tt> represents the maximum possible data value for the
+channel that the data will be written to.
+
+
+Source: <tt>/lib/range.c</tt>
+
+
+<p>
+<sect2>comedi_get_board_name()
+<p>
+
+<tt/char *comedi_get_board_name(comedi_t *it);/
+
+The function <tt/comedi_get_board_name/ returns a pointer
+to a string containing the name of the device. This pointer is
+valid until the comedi descriptor <tt/it/ is closed. This
+function returns <tt/NULL/ if there is an error.
+
+Source: <tt>/lib/get.c</tt>
+
+
+<p>
+<sect2>comedi_get_driver_name()
+<p>
+
+<tt/char *comedi_get_driver_name(comedi_t *it);/
+
+The function <tt/comedi_get_driver_name/ returns a pointer
+to a string containing the name of the driver being used by comedi
+for the comedi device represented by <tt/it/. This pointer is
+valid until the comedi descriptor <tt/it/ is closed. This
+function returns <tt/NULL/ if there is an error.
+
+Source: <tt>/lib/get.c</tt>
+
+
+<p>
+<sect2>comedi_get_maxdata()
+<p>
+
+<tt/lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int
+subdevice,unsigned int chan);/
+
+<p>
+The function <tt/comedi_get_maxdata()/ returns the maximum
+valid data value for channel <tt/chan/ of subdevice
+<tt/subdevice/ belonging to the comedi device <tt/it/
+This function returns 0 on error.
+
+Source: <tt>/lib/get.c</tt>
+
+
+<p>
+<sect2>comedi_get_n_channels()
+<p>
+
+<tt/int comedi_get_n_channels(comedi_t *it,unsigned int subdevice);/
+
+The function <tt>comedi_get_n_channels()</tt> returns the number
+of channels of the subdevice belonging to the comedi device <tt>it</tt>
+and having index <tt>subdevice</tt>. This function returns -1 on error.
+
+Source: <tt>/lib/get.c</tt>
+
+
+<p>
+<sect2>comedi_get_n_ranges()
+<p>
+
+<tt>int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice, unsigned int
+chan);</tt>
+
+The function <tt>comedi_get_n_ranges()</tt> returns the number
+of ranges of the channel <tt>chan</tt> belonging to the <tt>subdevice</tt>
+of the comedi device <tt>it</tt>. This function returns -1 on error.
+
+Source: <tt>/lib/range.c</tt>
+
+
+<p>
+<sect2>comedi_get_n_subdevices()
+<p>
+
+<tt>int comedi_get_n_subdevices(comedi_t *it);</tt>
+
+The function <tt>comedi_get_n_subdevices</tt> returns the
+number of subdevices associated with the comedi descriptor
+<tt>it</tt>, or -1 if there is an error.
+
+Source: <tt>/lib/get.c</tt>
+
+
+<p>
+<sect2>comedi_get_range()
+<p>
+
+<tt>comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,unsigned int chan,unsigned int
+range);</tt>
+
+The function <tt>comedi_get_range</tt> returns a pointer to a
+comedi_range structure that contains information that can be used to
+convert sample values to or from physical units. The pointer is valid
+until the comedi device <tt>it</tt> is closed. If there is an
+error, NULL is returned.
+
+Source: <tt>/lib/get.c</tt>
+
+<p>
+<sect2>comedi_get_rangetype()
+<p>
+
+<tt>int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,unsigned int
+chan);</tt>
+
+The function <tt>comedi_get_rangetype()</tt> returns an integer
+that represents the number of range specifications available for a
+particular channel <tt/chan/ of the subdevice <tt/subdevice/, as well as a conversion table to convert sample
+values to/from physical units.
+
+ The macro
+<tt>RANGE_LENGTH(rangetype)</tt>
+can be used to determine the number of range specifications for a given
+range type.
+
+Source: <tt>/lib/get.c</tt>
+
+<p>
+<sect2>comedi_get_subdevice_type()<label id="comedi_get_subdevice_type">
+<p>
+
+<tt>int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice);</tt>
+
+The function <tt>comedi_get_subdevice_type()</tt> returns an
+integer describing the type of subdevice that belongs to the comedi
+device <tt>it</tt> and has the index <tt>subdevice</tt>. The
+function returns -1 is there is an error.
+
+Valid subdevice types are:
+
+<itemize>
+<item><tt>COMEDI_SUBD_UNUSED</tt>
+Subdevice has no functionality, i.e., a place-holder.
+<item><tt>COMEDI_SUBD_AI</tt> Analog input
+<item><tt>COMEDI_SUBD_AO</tt> Analog output
+<item><tt>COMEDI_SUBD_DI</tt> Digital input
+<item><tt>COMEDI_SUBD_DO</tt> Digital output
+<item><tt>COMEDI_SUBD_DIO</tt>
+Digital input/output. Channels are configurable as to whether they
+are inputs or outputs.
+<item><tt>COMEDI_SUBD_COUNTER</tt> Counter
+<item><tt>COMEDI_SUBD_TIMER</tt> Timer
+<item><tt>COMEDI_SUBD_MEMORY</tt>
+Memory, e.g., EEPROM or dual-ported RAM
+<item><tt>COMEDI_SUBD_CALIB</tt>
+Calibration DACs
+<item><tt>COMEDI_SUBD_PROC</tt>
+Processor or DSP
+</itemize>
+
+Source: <tt>/lib/get.c</tt>
+
+<p>
+<sect2>comedi_get_timer() <it/(deprecated)/
+<p>
+
+<tt/int comedi_get_timer(comedi_t *it,unsigned int subdev, double
+freq,unsigned int *trigvar, double *actual_freq);/
+
+<p>
+The function <tt>comedi_get_timer</tt> converts the frequency <tt/freq/
+to a number suitable to send to the driver in a <tt/comedi_trig/
+structure. This function remains for compatibility with very
+old versions of Comedi, that converted sampling rates to timer
+values in the libary. This conversion is now done in the kernel,
+and every device has the timer type <tt/nanosec_timer/, indicating
+that timer values are simply a time specified in nanoseconds.
+
+<p>
+This function is deprecated and should not be used in new applications.
+
+<p>
+Source: <tt>/lib/timer.c</tt>
+
+<p>
+<sect2>comedi_get_version_code()
+<p>
+
+<tt/int comedi_get_version_code(comedi_t *it);/
+
+<p>
+The function <tt/comedi_get_version_code()/ returns the
+version code of the currently running comedi module. The version
+code is of the form 0x01072b, which is the version code for
+version 1.7.43.
+
+<p>
+This function is of limited usefulness. A typical mis-application
+of this function is to use it to determine if a certain feature is
+supported. If the application needs
+to know of the existence of a particular feature, an existence
+test function should be written and put in the libcomedi source.
+
+Source: <tt>/lib/get.c</tt>
+
+<p>
+<sect2>comedi_loglevel()
+<P>
+
+<tt>int comedi_loglevel(int loglevel);</tt>
+
+<p>
+This function affects the output of debugging and error messages
+from libcomedi. By increasing the loglevel, additional debugging
+information will be printed. This function returns the previous
+loglevel. Error messages and debugging are printed to the
+stream <tt/stderr/. The loglevel can also be affected by the
+environment variable COMEDI_LOGLEVEL.
+
+<p>
+In order to conserve resources, some debugging information is
+disabled when libcomedi is compiled.
+
+<p>The meaning of the loglevels is as follows:
+
+<itemize>
+<item><tt/COMEDILIB_LOGLEVEL=0/
+
+Comedilib prints nothing.
+
+<item><tt/COMEDILIB_LOGLEVEL=1/ (default)
+
+Comedilib only prints error messages when there is a
+self-consistency error (i.e., internal bug).
+
+<item><tt/COMEDILIB_LOGLEVEL=2/
+
+Comedilib prints an error message when an invalid
+parameter is passed to comedilib.
+
+<item><tt/COMEDILIB_LOGLEVEL=3/
+
+Comedilib prints an error message whenever an error is generated
+in the comedilib library or is generated in the C library when
+called by comedilib.
+
+<item><tt/COMEDILIB_LOGLEVEL=4/
+
+Comedilib prints a lot of debugging messages.
+
+</itemize>
+
+Bugs: Libcomedi doesn't currently have much debugging information.
+
+Source: <tt>/lib/error.c</tt>
+
+<p>
+<sect2>comedi_open()
+<p>
+
+<tt/comedi_t *comedi_open(char *filename);/
+
+Opens a comedi device specified by the filename <tt/filename/.
+Returns NULL on error. On sucess, it returns a handle that is
+given as a parameter to other libcomedi functions.
+
+<p>
+You are not supposed to have access to the internals of the
+<tt/comedi_t/ structure.
+
+Bugs: Not strictly identical to <tt/fopen/
+
+Source: <tt>/lib/comedi.c</tt>
+
+
+<p>
+<sect2>comedi_perror()<label id="comedi_perror">
+<p>
+
+<tt>void comedi_perror(const char *s);</tt>
+
+When a comedilib function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<tt><ref id="comedi_errno" name ="comedi_errno()"></tt>.
+ This error number can be
+ converted to a human-readable form by the functions
+<tt>comedi_perror()</tt>
+ and <tt><ref id="comedi_strerror" name ="comedi_strerror()"></tt>.
+
+These functions are intended to mimic the behavior of the
+standard C library functions <tt>perror()</tt>,
+<tt>strerror</tt>, and <tt>errno()</tt>. In particular,
+comedilib functions sometimes return an error that is generated
+inside the C library; the comedi error message in this case
+is the same as the C library.
+
+The function <tt>comedi_perror()</tt> prints an error
+message to stderr. The error message consists of the
+argument string, a colon, a space, a description of the error
+condition, and a new line.
+
+Bugs: Does not support internationalization.
+
+Source: <tt>/lib/error.c</tt>
+
+
+<p>
+<sect2>comedi_strerror()<label id="comedi_strerror">
+<p>
+
+<tt>*comedi_strerror(int errnum);</tt>
+
+When a comedilib function fails, it usually returns -1 or
+NULL, depending on the return type. An internal library
+variable stores an error number, which can be retrieved with
+<tt><ref id="comedi_errno" name ="comedi_errno()"></tt>. This error number can be
+converted to a human-readable form by the functions
+<tt><ref id="comedi_perror" name ="comedi_perror()"></tt>
+ and <tt>comedi_strerror()</tt>.
+
+These functions are intended to mimic the behavior of the
+standard C library functions <tt>perror()</tt>,
+<tt>strerror</tt>, and <tt>errno()</tt>. In particular,
+comedilib functions sometimes return an error that is generated
+inside the C library; the comedi error message in this case
+is the same as the C library.
+
+The function <tt>comedi_strerror()</tt> returns a pointer to a
+character string
+describing the comedilib error <tt>errnum</tt>. The persistence
+of the returned pointer is undefined, and should not be trusted
+after the next libcomedi call. An unrecognized error number will
+return a pointer to the string "undefined error", or similar.
+
+Bugs: Does not support internationalization.
+
+Source: <tt>/lib/error.c</tt>
+
+
+<p>
+<sect2>comedi_sv_init()
+<p>
+
+<tt/int comedi_sv_init(comedi_sv_t *sv,comedi_t *dev,unsigned int subd,
+unsigned int chan);/
+
+
+<tt/comedi_sv_init/ initializes the slow varying comedi structure
+<tt/sv/ of the device <tt/dev/, the subdevice <tt/subd/ (analog input) and
+the channel <tt/chan/.
+The slow varying comedi structure <tt/sv/ of type <tt><ref id="comedi_sv_t"
+name="comedi_sv_t"</tt>
+specifies the signal measurement. The default number of averaged
+samples is 100. Returns zero on success, -1 on error.
+
+Bugs: comedi_sv_* was very poorly designed.
+
+Source: <tt>/lib/sv.c</tt>
+
+
+<p>
+<sect2>comedi_sv_update()
+<p>
+
+<tt/int comedi_sv_update(comedi_sv_t *sv);/
+
+The function <tt/comedi_sv_update/ updates the slow varying comedi structure
+<tt/sv/.
+Returns zero on success, -1 on error.
+
+Source: <tt>/lib/sv.c</tt>
+
+
+<p>
+<sect2>int comedi_sv_measure()
+<p>
+
+<tt>int comedi_sv_measure(comedi_sv_t *it,double *data);</tt>
+
+<tt/comedi_sv_measure/ measures the slow variing signal. The measurement
+is specified by the slow varying comedi structure <tt/sv/, the result is
+stored in <tt/data/.
+On success returns the number of samples, -1 on error.
+
+Source: <tt>/lib/sv.c</tt>
+
+
+<p>
+<sect2>comedi_to_phys()<label id="comedi_to_phys">
+<p>
+
+<tt/double comedi_to_phys(lsampl_t data, comedi_range *rng,
+lsampl_t maxdata);/
+
+Converts data given in sample values (lsampl_t, between 0 and
+maxdata) into physical units (double). The parameter <tt/rng/
+represents the conversion information to use, and the parameter
+<tt/maxdata/ represents the maximum possible data value for the
+channel that the data was read.
+
+Source: <tt>/lib/range.c</tt>
+
+
+<p>
+<sect2>comedi_trigger() <it/(deprecated)/
+<p>
+
+<tt/int comedi_trigger(comedi_t *it,comedi_trig *trig);/
+
+The function <tt/comedi_trigger/ instructs comedi to
+perform the command specified by the <ref id="comedi_trig_struct" name
+="trigger structure"> <tt/trig/. Results depend on
+the particular command being issued. If there is an
+error, -1 is returned.
+
+Lifetime: removal at 1.0.
+
+Source: <tt>/lib/comedi.c</tt>
+
+
+
+
+
+
+
+
+
+
+
+
+
+<p>
+<sect2>comedi_get_timer()
+<p>
+
+<tscreen><verb>
+int comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,unsigned int *trigvar,
+ double *actual_freq);
+</verb></tscreen>
+
+
+<p>
+
+</article>
+