3 comedi library routines
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-8 David A. Schleef <ds@stm.lbl.gov>
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.
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.
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.
27 #include <sys/types.h>
31 #include <sys/ioctl.h>
36 #include <libinternal.h>
39 /* these functions download information from the comedi module. */
43 int get_subdevices(comedi_t *it)
50 s=malloc(sizeof(comedi_subdinfo)*it->n_subdevices);
51 ret=ioctl_subdinfo(it->fd,s);
54 r=it->subdevices=realloc(it->subdevices,
55 sizeof(subdevice)*it->n_subdevices);
57 memset(r,0,sizeof(subdevice)*it->n_subdevices);
59 for(i=0;i<it->n_subdevices;i++){
60 r[i].type = s[i].type;
61 if(r[i].type==COMEDI_SUBD_UNUSED)continue;
62 r[i].n_chan = s[i].n_chan;
63 r[i].subd_flags = s[i].subd_flags;
64 r[i].timer_type = s[i].timer_type;
65 r[i].len_chanlist = s[i].len_chanlist;
66 r[i].maxdata = s[i].maxdata;
67 r[i].flags = s[i].flags;
68 r[i].range_type = s[i].range_type;
70 if(r[i].subd_flags&SDF_FLAGS){
71 r[i].flags_list=malloc(sizeof(*r[i].flags_list)*r[i].n_chan);
72 debug_ptr(r[i].flags_list);
74 if(r[i].subd_flags&SDF_MAXDATA){
75 r[i].maxdata_list=malloc(sizeof(*r[i].maxdata_list)*r[i].n_chan);
76 debug_ptr(r[i].maxdata_list);
78 if(r[i].subd_flags&SDF_RANGETYPE){
79 r[i].range_type_list=malloc(sizeof(*r[i].range_type_list)*r[i].n_chan);
80 debug_ptr(r[i].range_type_list);
82 ret=ioctl_chaninfo(it->fd,i,r[i].maxdata_list,r[i].flags_list,r[i].range_type_list);
85 if(r[i].subd_flags&SDF_RANGETYPE){
86 r[i].rangeinfo_list=malloc(sizeof(*r[i].rangeinfo_list)*r[i].n_chan);
87 debug_ptr(r[i].rangeinfo_list);
88 for(j=0;j<r[i].n_chan;j++){
89 r[i].rangeinfo_list[j]=get_rangeinfo(it->fd,r[i].range_type_list[j]);
92 r[i].rangeinfo=get_rangeinfo(it->fd,r[i].range_type);
101 comedi_range *get_rangeinfo(int fd,unsigned int range_type)
107 kr=malloc(sizeof(comedi_krange)*RANGE_LENGTH(range_type));
108 r=malloc(sizeof(comedi_range)*RANGE_LENGTH(range_type));
110 ioctl_rangeinfo(fd,range_type,kr);
112 for(i=0;i<RANGE_LENGTH(range_type);i++){
113 r[i].min=kr[i].min*1e-6;
114 r[i].max=kr[i].max*1e-6;
115 r[i].unit=RF_UNIT(kr[i].flags);