/usr/share/doc/libcomedi-dev/html/writingprograms.html is in libcomedi-dev 0.10.2-4build7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>3. Writing Comedi programs</title><link rel="stylesheet" type="text/css" href="comedilib.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="index.html" title="Comedi"><link rel="up" href="index.html" title="Comedi"><link rel="prev" href="gettinginformation.html" title="2.2. Getting information about a card"><link rel="next" href="convertingsamples.html" title="3.2. Converting between integer data and physical units"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.
Writing <acronym class="acronym">Comedi</acronym> programs
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="gettinginformation.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="convertingsamples.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="writingprograms"></a>3.
Writing <a class="ulink" href="http://www.comedi.org" target="_top"><acronym class="acronym">Comedi</acronym></a> programs
</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="writingprograms.html#firstprogram">3.1.
Your first <acronym class="acronym">Comedi</acronym> program
</a></span></dt><dt><span class="section"><a href="convertingsamples.html">3.2.
Converting between integer data and physical units
</a></span></dt><dt><span class="section"><a href="secondprogram.html">3.3.
Your second <acronym class="acronym">Comedi</acronym> program
</a></span></dt><dt><span class="section"><a href="asyncprogram.html">3.4.
Asynchronous acquisition
</a></span></dt><dt><span class="section"><a href="ar01s03s05.html">3.5. Further examples</a></span></dt></dl></div><p>
This section describes how <a class="ulink" href="http://www.comedi.org" target="_top"><acronym class="acronym">Comedi</acronym></a>
can be used in an application, to communicate data with a set
of <a class="ulink" href="http://www.comedi.org" target="_top"><acronym class="acronym">Comedi</acronym></a> devices.
<a class="xref" href="acquisitionfunctions.html" title="4. Acquisition and configuration functions">Section 4</a> gives more details about
the various acquisition functions with which the application
programmer can perform data acquisition in <a class="ulink" href="http://www.comedi.org" target="_top"><acronym class="acronym">Comedi</acronym></a>.
</p><p>
Also don't forget to take a good look at the
<code class="filename">demo</code>
directory of the Comedilib source code. It contains lots of examples
for the basic functionalities of <a class="ulink" href="http://www.comedi.org" target="_top"><acronym class="acronym">Comedi</acronym></a>.
</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="firstprogram"></a>3.1.
Your first <a class="ulink" href="http://www.comedi.org" target="_top"><acronym class="acronym">Comedi</acronym></a> program
</h3></div></div></div><p>
This example requires a card that has analog or digital input. This
progam opens the device, gets the data, and prints it out:
</p><pre class="programlisting">
/*
* Tutorial example #1
* Part of Comedilib
*
* Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
*
* This file may be freely modified, distributed, and combined with
* other software, as long as proper attribution is given in the
* source code.
*/
#include <stdio.h> /* for printf() */
#include <comedilib.h>
int subdev = 0; /* change this to your input subdevice */
int chan = 0; /* change this to your channel */
int range = 0; /* more on this later */
int aref = AREF_GROUND; /* more on this later */
int main(int argc,char *argv[])
{
comedi_t *it;
int chan = 0;
lsampl_t data;
int retval;
it = comedi_open("/dev/comedi0");
if(it == NULL)
{
comedi_perror("comedi_open");
return -1;
}
retval = comedi_data_read(it, subdev, chan, range, aref, &data);
if(retval < 0)
{
comedi_perror("comedi_data_read");
return -1;
}
printf("%d\n", data);
return 0;
}
</pre><p>
</p><p>
The source code file for the above program can be found in Comedilib,
at <code class="filename">demo/tut1.c</code>. You can compile the program using
</p><pre class="screen">
cc tut1.c -lcomedi -lm -o tut1
</pre><p>
The
<code class="function">
<a class="link" href="func-ref-comedi-open.html" title="comedi_open">comedi_open</a>
</code> call can only be successful if the
<code class="filename">comedi0</code> device file is configured with a
valid <a class="ulink" href="http://www.comedi.org" target="_top"><acronym class="acronym">Comedi</acronym></a> driver. <a class="xref" href="install.html#cardconfiguration" title="2.1. Configuration">Section 2.1</a> explains
how this driver is linked to the <span class="quote">“<span class="quote">device file</span>”</span>.
</p><p>
The <em class="parameter"><code>range</code></em> variable tells
<a class="ulink" href="http://www.comedi.org" target="_top"><acronym class="acronym">Comedi</acronym></a> which gain to use when measuring an analog voltage. Since we
don't know (yet) which numbers are valid, or what each means, we'll
use <code class="literal">0</code>, because it won't cause errors. Likewise
with <em class="parameter"><code>aref</code></em>, which determines the
analog reference used.
</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="gettinginformation.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="convertingsamples.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.2.
Getting information about a card
</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 3.2.
Converting between integer data and physical units
</td></tr></table></div></body></html>
|