This commit is contained in:
David Schleef 2000-10-11 20:52:56 +00:00
parent d419596e0a
commit a966c3737d

View file

@ -52,8 +52,7 @@ int main(int argc,char *argv[])
<P>
<P>Should be understandable. Open the device, get the data,
print it out. This is basically the guts of <CODE>demo/inp.c</CODE>,
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
<P>
<BLOCKQUOTE><CODE>
@ -61,7 +60,6 @@ Compile it using
cc tut1.c -lcomedi -o tut1
</PRE>
</CODE></BLOCKQUOTE>
<P>Hopefully it works.
<P>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,
@ -85,18 +83,23 @@ you probably prefer to have this number translated to
a voltage. Naturally, as a good programmer, your first
question is: "How do I do this in a device-independent
manner?"
<P>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:
<P>RANGE_OFFSET(range_type)
RANGE_LENGTH(range_type)
<P>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
<P>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.
<P>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.)
<P>The largest sample value can be found using the function:
<P>comedi_get_maxdata()
<P>The number of available ranges can be found using the function:
<P>comedi_get_n_ranges()
<P>For each value of the range parameter for a particular
subdevice/channel, you can get range information using the
function:
<P>ptr=comedi_get_range(comedi_file,subdevice,channel,
range)
<P>which returns a pointer to a comedi_range structure.
@ -112,8 +115,7 @@ typedef struct{
}comedi_range;
</PRE>
</CODE></BLOCKQUOTE>
<P>As you might expect, ptr[range] is for range 'range',
which you provided to comedi_data_read() above. 'min' represents
<P>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,
@ -136,12 +138,6 @@ volts=comedi_to_phys(it,data,range,maxdata);
data=comedi_from_phys(it,volts,range,maxdata);
</PRE>
</CODE></BLOCKQUOTE>
<P>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>
<P>
<P>
@ -167,7 +163,7 @@ file=comedi_open("/dev/comedi0");
calls <CODE>open()</CODE>, like we did explicitly in a previous
section, but also fills the <CODE>comedi_t</CODE> structure with
lots of goodies -- information that we will need to use
soon.
soon.
<P>Specifically, we needed to know maxdata for a specific
subdevice/channel. How about:
<P>