added stub for pci-6014
[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 <stdlib.h>
11 #include <errno.h>
12 #include <string.h>
13 #include "examples.h"
14
15 void get_command_stuff(comedi_t *it,int s);
16
17 void help(void)
18 {
19         fprintf(stderr,"info </dev/comediN>\n");
20         exit(0);
21 }
22
23 char *tobinary(char *s,int bits,int n);
24
25 char *subdevice_types[]={
26         "unused",
27         "analog input",
28         "analog output",
29         "digital input",
30         "digital output",
31         "digital I/O",
32         "counter",
33         "timer",
34         "memory",
35         "calibration",
36         "processor",
37         "serial digital I/O"
38 };
39
40 comedi_t *it;
41 extern char *filename;
42
43
44 int main(int argc,char *argv[])
45 {
46         int i,j;
47         int n_subdevices,type;
48         int chan,n_chans;
49         int n_ranges;
50         comedi_range *rng;
51         
52         parse_options(argc,argv);
53
54         it=comedi_open(filename);
55         if(!it){
56                 fprintf(stderr,"cannot open %s\n",filename);
57                 exit(0);
58         }
59
60         printf("overall info:\n");
61         printf("  version code: 0x%06x\n",comedi_get_version_code(it));
62         printf("  driver name: %s\n",comedi_get_driver_name(it));
63         printf("  board name: %s\n",comedi_get_board_name(it));
64         printf("  number of subdevices: %d\n",n_subdevices=comedi_get_n_subdevices(it));
65         
66         for(i=0;i<n_subdevices;i++){
67                 printf("subdevice %d:\n",i);
68                 type=comedi_get_subdevice_type(it,i);
69                 printf("  type: %d (%s)\n",type,subdevice_types[type]);
70                 if(type==COMEDI_SUBD_UNUSED)
71                         continue;
72                 n_chans=comedi_get_n_channels(it,i);
73                 printf("  number of channels: %d\n",n_chans);
74                 if(!comedi_maxdata_is_chan_specific(it,i)){
75                         printf("  max data value: %d\n",comedi_get_maxdata(it,i,0));
76                 }else{
77                         printf("  max data value: (channel specific)\n");
78                         for(chan=0;chan<n_chans;chan++){
79                                 printf("    chan%d: %d\n",chan,
80                                         comedi_get_maxdata(it,i,chan));
81                         }
82                 }
83                 printf("  ranges:\n");
84                 if(!comedi_range_is_chan_specific(it,i)){
85                         n_ranges=comedi_get_n_ranges(it,i,0);
86                         printf("    all chans:");
87                         for(j=0;j<n_ranges;j++){
88                                 rng=comedi_get_range(it,i,0,j);
89                                 printf(" [%g,%g]",rng->min,rng->max);
90                         }
91                         printf("\n");
92                 }else{
93                         for(chan=0;chan<n_chans;chan++){
94                                 n_ranges=comedi_get_n_ranges(it,i,chan);
95                                 printf("    chan%d:",chan);
96                                 for(j=0;j<n_ranges;j++){
97                                         rng=comedi_get_range(it,i,chan,j);
98                                         printf(" [%g,%g]",rng->min,rng->max);
99                                 }
100                                 printf("\n");
101                         }
102                 }
103                 printf("  command:\n");
104                 get_command_stuff(it,i);
105         }
106         
107         return 0;
108 }
109
110 char *tobinary(char *s,int bits,int n)
111 {
112         int bit=1<<n;
113         char *t=s;
114         
115         for(;bit;bit>>=1)
116                 *t++=(bits&bit)?'1':'0';
117         *t=0;
118         
119         return s;
120 }
121
122 void probe_max_1chan(comedi_t *it,int s);
123
124 void get_command_stuff(comedi_t *it,int s)
125 {
126         comedi_cmd cmd;
127         char buf[100];
128
129         if(comedi_get_cmd_src_mask(it,s,&cmd)<0){
130                 printf("    not supported\n");
131         }else{
132                 printf("    start: %s\n",cmd_src(cmd.start_src,buf));
133                 printf("    scan_begin: %s\n",cmd_src(cmd.scan_begin_src,buf));
134                 printf("    convert: %s\n",cmd_src(cmd.convert_src,buf));
135                 printf("    scan_end: %s\n",cmd_src(cmd.scan_end_src,buf));
136                 printf("    stop: %s\n",cmd_src(cmd.stop_src,buf));
137         
138                 probe_max_1chan(it,s);
139         }
140 }
141
142 void probe_max_1chan(comedi_t *it,int s)
143 {
144         comedi_cmd cmd;
145         char buf[100];
146
147         printf("  command fast 1chan:\n");
148         if(comedi_get_cmd_generic_timed(it,s,&cmd,1)<0){
149                 printf("    not supported\n");
150         }else{
151                 printf("    start: %s %d\n",
152                         cmd_src(cmd.start_src,buf),cmd.start_arg);
153                 printf("    scan_begin: %s %d\n",
154                         cmd_src(cmd.scan_begin_src,buf),cmd.scan_begin_arg);
155                 printf("    convert: %s %d\n",
156                         cmd_src(cmd.convert_src,buf),cmd.convert_arg);
157                 printf("    scan_end: %s %d\n",
158                         cmd_src(cmd.scan_end_src,buf),cmd.scan_end_arg);
159                 printf("    stop: %s %d\n",
160                         cmd_src(cmd.stop_src,buf),cmd.stop_arg);
161         }
162 }
163