insert usleep() in loop
[comedilib.git] / demo / inpn.c
1 /*
2  * Multi-channel, multi-range one-shot input demo
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    This demo opens /dev/comedi0 and looks for an analog input
13    subdevice.  If it finds one, it measures one sample on each
14    channel for each input range.  The value NaN indicates that
15    the measurement was out of range.
16  */
17
18 #include <stdio.h>
19 #include <comedilib.h>
20 #include <fcntl.h>
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <getopt.h>
25 #include <ctype.h>
26 #include "examples.h"
27
28 comedi_t *device;
29
30
31 int main(int argc, char *argv[])
32 {
33         int n_chans,chan;
34         int n_ranges;
35         int range;
36         int maxdata;
37         lsampl_t data;
38         double voltage;
39
40         parse_options(argc,argv);
41
42         device=comedi_open(filename);
43         if(!device){
44                 comedi_perror(filename);
45                 exit(0);
46         }
47
48         subdevice=comedi_find_subdevice_by_type(device,COMEDI_SUBD_AI,0);
49         if(subdevice<0){
50                 printf("no analog input subdevice found\n");
51                 exit(0);
52         }
53
54         n_chans=comedi_get_n_channels(device,subdevice);
55         for(chan=0;chan<n_chans;chan++){
56                 printf("%d: ",chan);
57
58                 n_ranges=comedi_get_n_ranges(device,subdevice,chan);
59
60                 maxdata=comedi_get_maxdata(device,subdevice,chan);
61                 for(range=0;range<n_ranges;range++){
62                         comedi_data_read(device,subdevice,chan,range,aref,&data);
63                         voltage=comedi_to_phys(data,comedi_get_range(device,subdevice,chan,range),maxdata);
64                         printf("%g ",voltage);
65                 }
66                 printf("\n");
67         }
68         
69         exit(0);
70 }
71