3 header file for the comedi library routines
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1998-2002 David A. Schleef <ds@schleef.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser 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.
29 #include <comedilib_version.h>
30 #include <sys/ioctl.h>
38 /* Macros for swig to %include this file. */
40 #define SWIG_OUTPUT(x) OUTPUT
41 #define SWIG_INPUT(x) INPUT
42 #define SWIG_INOUT(x) INOUT
44 #define SWIG_OUTPUT(x) x
45 #define SWIG_INPUT(x) x
46 #define SWIG_INOUT(x) x
49 typedef struct comedi_t_struct comedi_t;
57 typedef struct comedi_sv_struct{
59 unsigned int subdevice;
66 /* number of measurements to average (for ai) */
72 enum comedi_oor_behavior {
73 COMEDI_OOR_NUMBER = 0,
80 comedi_t *comedi_open(const char *fn);
81 int comedi_close(comedi_t *it);
84 int comedi_loglevel(int loglevel);
85 void comedi_perror(const char *s);
86 const char *comedi_strerror(int errnum);
87 int comedi_errno(void);
88 int comedi_fileno(comedi_t *it);
91 enum comedi_oor_behavior comedi_set_global_oor_behavior(enum comedi_oor_behavior behavior);
94 int comedi_get_n_subdevices(comedi_t *it);
95 #define COMEDI_VERSION_CODE(a,b,c) (((a)<<16) | ((b)<<8) | (c))
96 int comedi_get_version_code(comedi_t *it);
97 const char *comedi_get_driver_name(comedi_t *it);
98 const char *comedi_get_board_name(comedi_t *it);
99 int comedi_get_read_subdevice(comedi_t *dev);
100 int comedi_get_write_subdevice(comedi_t *dev);
102 /* subdevice queries */
103 int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice);
104 int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd);
105 int comedi_get_subdevice_flags(comedi_t *it,unsigned int subdevice);
106 int comedi_get_n_channels(comedi_t *it,unsigned int subdevice);
107 int comedi_range_is_chan_specific(comedi_t *it,unsigned int subdevice);
108 int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice);
110 /* channel queries */
111 lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,
113 int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice,
115 comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,
116 unsigned int chan,unsigned int range);
117 int comedi_find_range(comedi_t *it,unsigned int subd,unsigned int chan,
118 unsigned int unit,double min,double max);
121 int comedi_get_buffer_size(comedi_t *it,unsigned int subdevice);
122 int comedi_get_max_buffer_size(comedi_t *it,unsigned int subdevice);
123 int comedi_set_buffer_size(comedi_t *it,unsigned int subdevice,
126 /* low-level stuff */
127 #ifdef _COMEDILIB_DEPRECATED
128 int comedi_trigger(comedi_t *it,comedi_trig *trig); /* deprecated */
130 int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il);
131 int comedi_do_insn(comedi_t *it,comedi_insn *insn);
132 int comedi_lock(comedi_t *it,unsigned int subdevice);
133 int comedi_unlock(comedi_t *it,unsigned int subdevice);
136 double comedi_to_phys(lsampl_t data,comedi_range *rng,lsampl_t maxdata);
137 lsampl_t comedi_from_phys(double data,comedi_range *rng,lsampl_t maxdata);
138 int comedi_sampl_to_phys(double *dest, int dst_stride, sampl_t *src,
139 int src_stride, comedi_range *rng, lsampl_t maxdata, int n);
140 int comedi_sampl_from_phys(sampl_t *dest,int dst_stride,double *src,
141 int src_stride, comedi_range *rng, lsampl_t maxdata, int n);
143 /* syncronous stuff */
144 int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
145 unsigned int range,unsigned int aref,lsampl_t *SWIG_OUTPUT(data));
146 int comedi_data_read_n(comedi_t *it,unsigned int subd,unsigned int chan,
147 unsigned int range,unsigned int aref,lsampl_t *SWIG_OUTPUT(data), unsigned int n);
148 int comedi_data_read_hint(comedi_t *it,unsigned int subd,unsigned int chan,
149 unsigned int range,unsigned int aref);
150 int comedi_data_read_delayed(comedi_t *it,unsigned int subd,unsigned int chan,
151 unsigned int range,unsigned int aref,lsampl_t *SWIG_OUTPUT(data), unsigned int nano_sec);
152 int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
153 unsigned int range,unsigned int aref,lsampl_t data);
154 int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned int chan,
156 int comedi_dio_get_config(comedi_t *it,unsigned int subd,unsigned int chan,
157 unsigned int *SWIG_OUTPUT(dir));
158 int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan,
159 unsigned int *SWIG_OUTPUT(bit));
160 int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,
162 int comedi_dio_bitfield2(comedi_t *it,unsigned int subd,
163 unsigned int write_mask, unsigned int *SWIG_INOUT(bits), unsigned int base_channel);
164 /* Should be moved to _COMEDILIB_DEPRECATED once bindings for other languages are updated
165 * to use comedi_dio_bitfield2() instead.*/
166 int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
167 unsigned int write_mask, unsigned int *SWIG_INOUT(bits));
169 /* slowly varying stuff */
170 int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan);
171 int comedi_sv_update(comedi_sv_t *it);
172 int comedi_sv_measure(comedi_sv_t *it,double *SWIG_OUTPUT(data));
174 /* streaming I/O (commands) */
176 int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice,
177 comedi_cmd *SWIG_INOUT(cmd));
178 int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice,
179 comedi_cmd *SWIG_INOUT(cmd), unsigned chanlist_len, unsigned scan_period_ns);
180 int comedi_cancel(comedi_t *it,unsigned int subdevice);
181 int comedi_command(comedi_t *it,comedi_cmd *cmd);
182 int comedi_command_test(comedi_t *it,comedi_cmd *SWIG_INOUT(cmd));
183 int comedi_poll(comedi_t *dev,unsigned int subdevice);
187 int comedi_set_max_buffer_size(comedi_t *it, unsigned int subdev,
188 unsigned int max_size);
189 int comedi_get_buffer_contents(comedi_t *it, unsigned int subdev);
190 int comedi_mark_buffer_read(comedi_t *it, unsigned int subdev,
192 int comedi_mark_buffer_written(comedi_t *it, unsigned int subdev,
194 int comedi_get_buffer_offset(comedi_t *it, unsigned int subdev);
196 #ifdef _COMEDILIB_DEPRECATED
198 * The following functions are deprecated and should not be used.
200 int comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,
201 unsigned int *trigvar,double *actual_freq);
202 int comedi_timed_1chan(comedi_t *it,unsigned int subdev,unsigned int chan,
203 unsigned int range, unsigned int aref,double freq,
204 unsigned int n_samples,double *data);
205 int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,
210 #ifndef _COMEDILIB_STRICT_ABI
212 The following prototypes are _NOT_ part of the Comedilib ABI, and
213 may change in future versions without regard to source or binary
214 compatibility. In practice, this is a holding place for the next
215 library ABI version change.
217 /* structs and functions used for parsing calibration files */
220 unsigned int subdevice;
221 unsigned int channel;
224 #define COMEDI_MAX_NUM_POLYNOMIAL_COEFFICIENTS 4
227 double coefficients[COMEDI_MAX_NUM_POLYNOMIAL_COEFFICIENTS];
228 double expansion_origin;
230 } comedi_polynomial_t;
233 comedi_polynomial_t *to_phys;
234 comedi_polynomial_t *from_phys;
236 #define CS_MAX_AREFS_LENGTH 4
239 unsigned int subdevice;
240 unsigned int *channels;
241 unsigned int num_channels;
242 unsigned int *ranges;
243 unsigned int num_ranges;
244 unsigned int arefs[ CS_MAX_AREFS_LENGTH ];
245 unsigned int num_arefs;
246 comedi_caldac_t *caldacs;
247 unsigned int num_caldacs;
248 comedi_softcal_t soft_calibration;
249 } comedi_calibration_setting_t;
255 comedi_calibration_setting_t *settings;
256 unsigned int num_settings;
257 } comedi_calibration_t;
259 comedi_calibration_t* comedi_parse_calibration_file( const char *cal_file_path );
260 int comedi_apply_parsed_calibration( comedi_t *dev, unsigned int subdev, unsigned int channel,
261 unsigned int range, unsigned int aref, const comedi_calibration_t *calibration );
262 char* comedi_get_default_calibration_path( comedi_t *dev );
263 void comedi_cleanup_calibration( comedi_calibration_t *calibration );
264 int comedi_apply_calibration( comedi_t *dev, unsigned int subdev, unsigned int channel,
265 unsigned int range, unsigned int aref, const char *cal_file_path);
267 /* New stuff to provide conversion between integers and physical values that
268 * can support software calibrations. */
269 enum comedi_conversion_direction
274 int comedi_get_softcal_converter(
275 unsigned subdevice, unsigned channel, unsigned range,
276 enum comedi_conversion_direction direction,
277 const comedi_calibration_t *calibration, comedi_polynomial_t* SWIG_OUTPUT(polynomial));
278 int comedi_get_hardcal_converter(
279 comedi_t *dev, unsigned subdevice, unsigned channel, unsigned range,
280 enum comedi_conversion_direction direction, comedi_polynomial_t* SWIG_OUTPUT(polynomial));
281 double comedi_to_physical(lsampl_t data,
282 const comedi_polynomial_t *conversion_polynomial);
283 lsampl_t comedi_from_physical(double data,
284 const comedi_polynomial_t *conversion_polynomial);
286 int comedi_internal_trigger(comedi_t *dev, unsigned subd, unsigned trignum);
287 /* INSN_CONFIG wrappers */
288 int comedi_arm(comedi_t *device, unsigned subdevice, unsigned source);
289 int comedi_reset(comedi_t *device, unsigned subdevice);
290 int comedi_get_clock_source(comedi_t *device, unsigned subdevice, unsigned channel, unsigned *SWIG_OUTPUT(clock), unsigned *SWIG_OUTPUT(period_ns));
291 int comedi_get_gate_source(comedi_t *device, unsigned subdevice, unsigned channel,
292 unsigned gate, unsigned *SWIG_OUTPUT(source));
293 int comedi_get_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned *SWIG_OUTPUT(routing));
294 int comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned channel, unsigned mode_bits);
295 int comedi_set_clock_source(comedi_t *device, unsigned subdevice, unsigned channel, unsigned clock, unsigned period_ns);
296 int comedi_set_filter(comedi_t *device, unsigned subdevice, unsigned channel, unsigned filter);
297 int comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned channel, unsigned gate_index, unsigned gate_source);
298 int comedi_set_other_source(comedi_t *device, unsigned subdevice, unsigned channel,
299 unsigned other, unsigned source);
300 int comedi_set_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned routing);
301 int comedi_get_hardware_buffer_size(comedi_t *device, unsigned subdevice, enum comedi_io_direction direction);