~ubuntu-branches/ubuntu/intrepid/comedilib/intrepid

« back to all changes in this revision

Viewing changes to demo/info.c

  • Committer: Bazaar Package Importer
  • Author(s): David Schleef
  • Date: 2003-09-23 18:11:12 UTC
  • Revision ID: james.westby@ubuntu.com-20030923181112-sat05jyh702rb1at
Tags: upstream-0.7.21
ImportĀ upstreamĀ versionĀ 0.7.21

Show diffs side-by-side

added added

removed removed

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