5 COMEDILIB - Linux Control and Measurement Device Interface Library
6 Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation, version 2.1
13 This library 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 GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <sys/types.h>
35 #include <libinternal.h>
38 int comedi_dio_config(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int io)
42 if(!valid_chan(it,subdev,chan))
45 s=it->subdevices+subdev;
46 if(s->type!=COMEDI_SUBD_DIO)
49 if(io!=COMEDI_INPUT && io!=COMEDI_OUTPUT)
52 if(it->has_insnlist_ioctl){
56 memset(&insn,0,sizeof(insn));
57 insn.insn = INSN_CONFIG;
61 insn.chanspec = CR_PACK(chan,0,0);
64 return comedi_do_insn(it,&insn);
70 memset(&trig,0,sizeof(trig));
71 trig.flags=TRIG_CONFIG|TRIG_WRITE;
76 trig.data=(sampl_t *)&data;
78 return comedi_trigger(it,&trig);
82 int comedi_dio_read(comedi_t *it,unsigned int subdev,unsigned int chan,
88 if(!valid_chan(it,subdev,chan))
91 s = it->subdevices+subdev;
92 if(s->type!=COMEDI_SUBD_DIO &&
93 s->type!=COMEDI_SUBD_DO &&
94 s->type!=COMEDI_SUBD_DI)
97 if(it->has_insnlist_ioctl){
101 memset(&insn,0,sizeof(insn));
102 insn.insn = INSN_READ;
105 insn.subdev = subdev;
106 insn.chanspec = CR_PACK(chan,0,0);
108 ret = comedi_do_insn(it,&insn);
117 memset(&trig,0,sizeof(trig));
122 trig.data=(sampl_t *)&data;
124 ret=comedi_trigger(it,&trig);
126 if(ret>=0 && val)*val=data;
132 int comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan,
137 if(!valid_chan(it,subdev,chan))
140 s = it->subdevices+subdev;
141 if(s->type!=COMEDI_SUBD_DIO &&
142 s->type!=COMEDI_SUBD_DO)
145 if(it->has_insnlist_ioctl){
149 memset(&insn,0,sizeof(insn));
150 insn.insn = INSN_WRITE;
153 insn.subdev = subdev;
154 insn.chanspec = CR_PACK(chan,0,0);
158 return comedi_do_insn(it,&insn);
165 memset(&trig,0,sizeof(trig));
168 trig.flags=TRIG_WRITE;
171 trig.data=(sampl_t *)&data;
173 return comedi_trigger(it,&trig);
177 int comedi_dio_bitfield(comedi_t *it,unsigned int subdev,unsigned int mask,unsigned int *bits)
183 if(!valid_subd(it,subdev))
186 s=it->subdevices+subdev;
188 if(s->type!=COMEDI_SUBD_DIO && s->type!=COMEDI_SUBD_DO &&
189 s->type!=COMEDI_SUBD_DI)
192 if(s->has_insn_bits){
196 memset(&insn,0,sizeof(insn));
198 insn.insn = INSN_BITS;
201 insn.subdev = subdev;
206 ret = comedi_do_insn(it,&insn);
214 unsigned int i,n_chan;
216 n_chan=comedi_get_n_channels(it,subdev);
217 if(n_chan>32)n_chan=32;
218 for(i=0,m=1;i<n_chan;i++,m<<=1){
221 ret=comedi_dio_write(it,subdev,i,bit);
223 ret=comedi_dio_read(it,subdev,i,&bit);