dio fixes
[comedilib.git] / lib / get.c
1 /*
2     lib/get.c
3     comedi library routines
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1997-8 David A. Schleef <ds@stm.lbl.gov>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 */
23
24 #include <stdio.h>
25 #include <math.h>
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31 #include <sys/ioctl.h>
32 #include <errno.h>
33 #include <comedi.h>
34 #include <string.h>
35
36 #include <libinternal.h>
37
38
39 int comedi_get_n_subdevices(comedi_t *it)
40 {
41         if(!valid_dev(it))
42                 return -1;
43
44         return it->n_subdevices;
45 }
46
47 int comedi_get_version_code(comedi_t *it)
48 {
49         if(!valid_dev(it))
50                 return -1;
51
52         return it->devinfo.version_code;
53 }
54
55 char *comedi_get_driver_name(comedi_t *it)
56 {
57         if(!valid_dev(it))
58                 return NULL;
59
60         return it->devinfo.driver_name;
61 }
62
63 char *comedi_get_board_name(comedi_t *it)
64 {
65         if(!valid_dev(it))
66                 return NULL;
67
68         return it->devinfo.board_name;
69 }
70
71 int comedi_get_subdevice_type(comedi_t *it,unsigned int subd)
72 {
73         if(!valid_dev(it))
74                 return -1;
75
76         return it->subdevices[subd].type;
77 }
78
79 int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd)
80 {
81         if(!valid_subd(it,subd))
82                 return -1;
83
84         for(;subd<it->n_subdevices;subd++){
85                 if(it->subdevices[subd].type==type)
86                         return subd;
87         }
88         return -1;
89 }
90
91
92 int comedi_get_n_channels(comedi_t *it,unsigned int subd)
93 {
94         if(!valid_subd(it,subd))
95                 return -1;
96
97         return it->subdevices[subd].n_chan;
98 }
99
100
101 /* */
102
103 lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,unsigned int chan)
104 {
105         if(!valid_chan(it,subdevice,chan))
106                 return 0;
107
108         if(it->subdevices[subdevice].maxdata_list)
109                 return it->subdevices[subdevice].maxdata_list[chan];
110
111         return it->subdevices[subdevice].maxdata;
112 }
113
114 int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice)
115 {
116         if(it->subdevices[subdevice].maxdata_list)
117                 return 1;
118         return 0;
119 }
120
121 int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,unsigned int chan)
122 {
123         if(!valid_chan(it,subdevice,chan))
124                 return -1;
125
126         if(it->subdevices[subdevice].range_type_list)
127                 return it->subdevices[subdevice].range_type_list[chan];
128
129         return it->subdevices[subdevice].range_type;
130 }
131
132
133 comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,unsigned int chan,unsigned int range)
134 {
135         int range_type;
136
137         if(!valid_chan(it,subdevice,chan))
138                 return NULL;
139
140         range_type=comedi_get_rangetype(it,subdevice,chan);
141
142         if(range>=RANGE_LENGTH(range_type))
143                 return NULL;
144
145         if(it->subdevices[subdevice].rangeinfo_list)
146                 return it->subdevices[subdevice].rangeinfo_list[chan]+range;
147
148         return it->subdevices[subdevice].rangeinfo+range;
149 }
150
151
152