added
[comedilib.git] / demo / tut2.c
1 /*
2  * Tutorial example #2
3  * Part of Comedilib
4  *
5  * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
6  *
7  * This file may be freely modified, distributed, and combined with
8  * other software, as long as proper attribution is given in the
9  * source code.
10  */
11
12 #include <stdio.h>              /* for printf() */
13 #include <comedilib.h>
14
15 int subdev = 0;                 /* change this to your input subdevice */
16 int chan = 0;                   /* change this to your channel */
17 int range = 0;                  /* more on this later */
18 int aref = AREF_GROUND;         /* more on this later */
19
20 int main(int argc, char *argv[])
21 {
22         comedi_t *cf;
23         lsampl_t data;
24         int maxdata;
25         double volts;
26         comedi_range *cr;
27
28         cf = comedi_open("/dev/comedi0");
29         maxdata = comedi_get_maxdata(cf, subdev, chan);
30         cr = comedi_get_range(cf, subdev, chan, range);
31         comedi_data_read(cf, subdev, chan, range, aref, &data);
32         volts = comedi_to_phys(data, cr, maxdata);
33         printf("%d %g\n", data, volts);
34
35         return 0;
36 }