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 int comedi_dio_config(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int io)
44 if(!valid_chan(it,subdev,chan))
47 if(it->subdevices[subdev].type!=COMEDI_SUBD_DIO)
50 if(io!=COMEDI_INPUT && io!=COMEDI_OUTPUT)
53 memset(&trig,0,sizeof(trig));
54 trig.flags=TRIG_CONFIG|TRIG_WRITE;
59 trig.data=(sampl_t *)&data;
61 return ioctl_trigger(it->fd,&trig);
64 int comedi_dio_read(comedi_t *it,unsigned int subdev,unsigned int chan,
71 if(!valid_chan(it,subdev,chan))
74 if(it->subdevices[subdev].type!=COMEDI_SUBD_DIO &&
75 it->subdevices[subdev].type!=COMEDI_SUBD_DO &&
76 it->subdevices[subdev].type!=COMEDI_SUBD_DI)
79 memset(&trig,0,sizeof(trig));
84 trig.data=(sampl_t *)&data;
86 ret=ioctl_trigger(it->fd,&trig);
88 if(ret>=0 && val)*val=data;
93 int comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan,
99 if(!valid_chan(it,subdev,chan))
102 if(it->subdevices[subdev].type!=COMEDI_SUBD_DIO &&
103 it->subdevices[subdev].type!=COMEDI_SUBD_DO)
108 memset(&trig,0,sizeof(trig));
111 trig.flags=TRIG_WRITE;
114 trig.data=(sampl_t *)&data;
116 return ioctl_trigger(it->fd,&trig);
119 int comedi_dio_bitfield(comedi_t *it,unsigned int subdev,unsigned int mask,unsigned int *bits)
122 unsigned int i,n_chan;
126 if(!valid_subd(it,subdev))
129 if(it->subdevices[subdev].type!=COMEDI_SUBD_DIO &&
130 it->subdevices[subdev].type!=COMEDI_SUBD_DO &&
131 it->subdevices[subdev].type!=COMEDI_SUBD_DI)
134 s=it->subdevices+subdev;
136 n_chan=comedi_get_n_channels(it,subdev);
137 if(n_chan>32)n_chan=32;
138 for(i=0,m=1;i<n_chan;i++,m<<=1){
141 ret=comedi_dio_write(it,subdev,i,bit);
143 ret=comedi_dio_read(it,subdev,i,&bit);