3
functions for reading/writing data
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>
31
#include <sys/ioctl.h>
35
#include "libinternal.h"
38
EXPORT_ALIAS_DEFAULT(_comedi_data_write,comedi_data_write,0.7.18);
39
int _comedi_data_write(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range,
40
unsigned int aref,lsampl_t data)
44
if(!valid_chan(it,subdev,chan))
47
s=it->subdevices+subdev;
49
if(it->has_insnlist_ioctl){
52
memset(&insn,0,sizeof(insn));
54
insn.insn = INSN_WRITE;
58
insn.chanspec = CR_PACK(chan,range,aref);
60
return comedi_do_insn(it,&insn);
73
chan=CR_PACK(chan,range,aref);
76
if(it->subdevices[subdev].subd_flags & SDF_LSAMPL){
77
cmd.data=(sampl_t *)(&data);
83
return comedi_ioctl(it->fd, COMEDI_TRIG, (unsigned long)&cmd);
87
static int comedi_internal_data_read_n(comedi_t *it,
88
unsigned int subdev, unsigned int chanspec, lsampl_t *data,
93
if(!valid_subd(it,subdev))
96
s = it->subdevices + subdev;
98
if(it->has_insnlist_ioctl){
101
memset(&insn,0,sizeof(insn));
103
insn.insn = INSN_READ;
106
insn.subdev = subdev;
107
insn.chanspec = chanspec;
109
return comedi_do_insn(it,&insn);
125
cmd.chanlist=&chanspec;
126
if(s->subd_flags & SDF_LSAMPL){
127
cmd.data=(sampl_t *)data;
132
ret = comedi_ioctl(it->fd, COMEDI_TRIG, (unsigned long)&cmd);
136
if(!(s->subd_flags & SDF_LSAMPL)){
137
for( i = 0; i < n; i++)
145
EXPORT_ALIAS_DEFAULT(_comedi_data_read_n,comedi_data_read_n,0.7.18);
146
int _comedi_data_read_n(comedi_t *it, unsigned int subdev,
147
unsigned int chan, unsigned int range,
148
unsigned int aref, lsampl_t *data, unsigned int n)
150
static const int max_chunk_size = 100;
151
unsigned int chunk_size;
152
unsigned int sample_count = 0;
157
if( n > max_chunk_size)
158
chunk_size = max_chunk_size;
161
retval = comedi_internal_data_read_n(it, subdev,
162
CR_PACK(chan, range, aref),
163
data+sample_count, chunk_size);
164
if( retval < 0 ) return retval;
166
sample_count += chunk_size;
171
EXPORT_ALIAS_DEFAULT(_comedi_data_read,comedi_data_read,0.7.18);
172
int _comedi_data_read(comedi_t *it, unsigned int subdev, unsigned int chan,
173
unsigned int range, unsigned int aref, lsampl_t *data)
175
return comedi_internal_data_read_n(it, subdev,
176
CR_PACK(chan, range, aref), data, 1);
179
EXPORT_ALIAS_DEFAULT(_comedi_data_read_hint,comedi_data_read_hint,0.7.19);
180
int _comedi_data_read_hint(comedi_t *it, unsigned int subdev,
181
unsigned int chan, unsigned int range, unsigned int aref)
184
return comedi_internal_data_read_n(it, subdev,
185
CR_PACK(chan, range, aref), &dummy_data, 0);
188
EXPORT_ALIAS_DEFAULT(_comedi_data_read_delayed,comedi_data_read_delayed,0.7.19);
189
int _comedi_data_read_delayed( comedi_t *it, unsigned int subdev,
190
unsigned int chan, unsigned int range, unsigned int aref,
191
lsampl_t *data, unsigned int nano_sec)
194
comedi_insnlist ilist;
196
lsampl_t delay = nano_sec;
198
if( !valid_chan( it, subdev, chan ) )
201
s = it->subdevices + subdev;
203
memset( insn, 0, sizeof(insn) );
204
memset( &ilist, 0, sizeof(ilist) );
206
// setup, no conversions
207
insn[0].insn = INSN_READ;
210
insn[0].subdev = subdev;
211
insn[0].chanspec = CR_PACK( chan, range, aref );
213
insn[1].insn = INSN_WAIT;
215
insn[1].data = &delay;
217
insn[2].insn = INSN_READ;
220
insn[2].subdev = subdev;
221
insn[2].chanspec = CR_PACK( chan, range, aref );
224
ilist.n_insns = sizeof(insn) / sizeof(insn[0]);
226
return comedi_do_insnlist(it, &ilist);