0040d7dc0e6746068e11aa756ed5d0ee954c636e
[comedilib.git] / demo / info.c
1 /*
2    This demo reads information about a comedi device and
3    displays the information in a human-readable form.
4  */
5
6 #include <stdio.h>
7 #include <comedilib.h>
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include <sys/ioctl.h>
11 #include <errno.h>
12
13 void help(void)
14 {
15         fprintf(stderr,"info </dev/comediN>\n");
16         exit(0);
17 }
18
19 char *tobinary(char *s,int bits,int n);
20
21 char *subdevice_types[]={
22         "unused",
23         "analog input",
24         "analog output",
25         "digital input",
26         "digital output",
27         "digital I/O",
28         "counter",
29         "timer",
30         "memory",
31         "calibration",
32         "processor"
33 };
34
35 comedi_t *it;
36 extern char *filename;
37
38
39 int main(int argc,char *argv[])
40 {
41         int i;
42         int n_subdevices,type;
43         
44         parse_options(argc,argv);
45
46         it=comedi_open(filename);
47         if(!it){
48                 fprintf(stderr,"cannot open %s\n",filename);
49                 exit(0);
50         }
51
52         printf("overall info:\n");
53         printf("  version code: 0x%06x\n",comedi_get_version_code(it));
54         printf("  driver name: %s\n",comedi_get_driver_name(it));
55         printf("  board name: %s\n",comedi_get_board_name(it));
56         printf("  number of subdevices: %d\n",n_subdevices=comedi_get_n_subdevices(it));
57         
58         for(i=0;i<n_subdevices;i++){
59                 printf("subdevice %d:\n",i);
60                 type=comedi_get_subdevice_type(it,i);
61                 printf("  type: %d (%s)\n",type,subdevice_types[type]);
62                 printf("  number of channels: %d\n",comedi_get_n_channels(it,i));
63                 printf("  max data value: %d\n",comedi_get_maxdata(it,i,0));
64         }
65         
66         return 0;
67 }
68
69 char *tobinary(char *s,int bits,int n)
70 {
71         int bit=1<<n;
72         char *t=s;
73         
74         for(;bit;bit>>=1)
75                 *t++=(bits&bit)?'1':'0';
76         *t=0;
77         
78         return s;
79 }
80