Changed comedi_set_calibration() to comedi_apply_calibration(), and
[comedilib.git] / include / comedilib.h
1 /*
2     include/comedilib.h
3     header file for the comedi library routines
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1998-2002 David A. Schleef <ds@schleef.org>
7
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.
12
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.
17
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.
21
22 */
23
24
25 #ifndef _COMEDILIB_H
26 #define _COMEDILIB_H
27
28 #include <comedi.h>
29 #include <sys/ioctl.h>
30 #include <fcntl.h>
31 #include <stdio.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 typedef struct comedi_t_struct comedi_t;
38
39 typedef struct{
40         double min;
41         double max;
42         unsigned int unit;
43 }comedi_range;
44
45 typedef struct comedi_sv_struct{
46         comedi_t *dev;
47         unsigned int subdevice;
48         unsigned int chan;
49
50         /* range policy */
51         int range;
52         int aref;
53
54         /* number of measurements to average (for ai) */
55         int n;
56
57         lsampl_t maxdata;
58 }comedi_sv_t;
59
60 enum comedi_oor_behavior {
61         COMEDI_OOR_NUMBER = 0,
62         COMEDI_OOR_NAN
63 };
64
65
66
67
68 comedi_t *comedi_open(const char *fn);
69 int comedi_close(comedi_t *it);
70
71 /* logging */
72 int comedi_loglevel(int loglevel);
73 void comedi_perror(const char *s);
74 char *comedi_strerror(int errnum);
75 int comedi_errno(void);
76 int comedi_fileno(comedi_t *it);
77
78 /* global behavior */
79 enum comedi_oor_behavior comedi_set_global_oor_behavior(enum comedi_oor_behavior behavior);
80
81 /* device queries */
82 int comedi_get_n_subdevices(comedi_t *it);
83 int comedi_get_version_code(comedi_t *it);
84 char *comedi_get_driver_name(comedi_t *it);
85 char *comedi_get_board_name(comedi_t *it);
86 int comedi_get_read_subdevice(comedi_t *dev);
87 int comedi_get_write_subdevice(comedi_t *dev);
88
89 /* subdevice queries */
90 int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice);
91 int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd);
92 int comedi_get_subdevice_flags(comedi_t *it,unsigned int subdevice);
93 int comedi_get_n_channels(comedi_t *it,unsigned int subdevice);
94 int comedi_range_is_chan_specific(comedi_t *it,unsigned int subdevice);
95 int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice);
96
97 /* channel queries */
98 lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,
99         unsigned int chan);
100 int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice,
101         unsigned int chan);
102 comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,
103         unsigned int chan,unsigned int range);
104 int comedi_find_range(comedi_t *it,unsigned int subd,unsigned int chan,
105         unsigned int unit,double min,double max);
106
107 /* buffer queries */
108 int comedi_get_buffer_size(comedi_t *it,unsigned int subdevice);
109 int comedi_get_max_buffer_size(comedi_t *it,unsigned int subdevice);
110 int comedi_set_buffer_size(comedi_t *it,unsigned int subdevice,
111         unsigned int len);
112
113 /* low-level stuff */
114 #ifdef _COMEDILIB_DEPRECATED
115 int comedi_trigger(comedi_t *it,comedi_trig *trig); /* deprecated */
116 #endif
117 int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il);
118 int comedi_do_insn(comedi_t *it,comedi_insn *insn);
119 int comedi_lock(comedi_t *it,unsigned int subdevice);
120 int comedi_unlock(comedi_t *it,unsigned int subdevice);
121
122 /* physical units */
123 double comedi_to_phys(lsampl_t data,comedi_range *rng,lsampl_t maxdata);
124 lsampl_t comedi_from_phys(double data,comedi_range *rng,lsampl_t maxdata);
125 int comedi_sampl_to_phys(double *dest, int dst_stride, sampl_t *src,
126         int src_stride, comedi_range *rng, lsampl_t maxdata, int n);
127 int comedi_sampl_from_phys(sampl_t *dest,int dst_stride,double *src,
128         int src_stride, comedi_range *rng, lsampl_t maxdata, int n);
129
130 /* syncronous stuff */
131 int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
132         unsigned int range,unsigned int aref,lsampl_t *data);
133 int comedi_data_read_n(comedi_t *it,unsigned int subd,unsigned int chan,
134         unsigned int range,unsigned int aref,lsampl_t *data, unsigned int n);
135 int comedi_data_read_hint(comedi_t *it,unsigned int subd,unsigned int chan,
136         unsigned int range,unsigned int aref);
137 int comedi_data_read_delayed(comedi_t *it,unsigned int subd,unsigned int chan,
138         unsigned int range,unsigned int aref,lsampl_t *data, unsigned int nano_sec);
139 int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
140         unsigned int range,unsigned int aref,lsampl_t data);
141 int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned int chan,
142         unsigned int dir);
143 int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan,
144         unsigned int *bit);
145 int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,
146         unsigned int bit);
147 int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
148         unsigned int write_mask, unsigned int *bits);
149
150 /* slowly varying stuff */
151 int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan);
152 int comedi_sv_update(comedi_sv_t *it);
153 int comedi_sv_measure(comedi_sv_t *it,double *data);
154
155 /* streaming I/O (commands) */
156
157 int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice,
158         comedi_cmd *cmd);
159 int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice,
160         comedi_cmd *cmd,unsigned int ns);
161 int comedi_cancel(comedi_t *it,unsigned int subdevice);
162 int comedi_command(comedi_t *it,comedi_cmd *cmd);
163 int comedi_command_test(comedi_t *it,comedi_cmd *cmd);
164 int comedi_poll(comedi_t *dev,unsigned int subdevice);
165
166 /* buffer control */
167
168 int comedi_set_max_buffer_size(comedi_t *it, unsigned int subdev,
169         unsigned int max_size);
170 int comedi_get_buffer_contents(comedi_t *it, unsigned int subdev);
171 int comedi_mark_buffer_read(comedi_t *it, unsigned int subdev,
172         unsigned int bytes);
173 int comedi_get_buffer_offset(comedi_t *it, unsigned int subdev);
174
175 #ifdef _COMEDILIB_DEPRECATED
176 /*
177  * The following functions are deprecated and should not be used.
178  */
179 int comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,
180         unsigned int *trigvar,double *actual_freq);
181 int comedi_timed_1chan(comedi_t *it,unsigned int subdev,unsigned int chan,
182         unsigned int range, unsigned int aref,double freq,
183         unsigned int n_samples,double *data);
184 int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,
185         unsigned int chan);
186 #endif
187
188
189 #ifndef _COMEDILIB_STRICT_ABI
190 /*
191    The following prototypes are _NOT_ part of the Comedilib ABI, and
192    may change in future versions without regard to source or binary
193    compatibility.  In practice, this is a holding place for the next
194    library ABI version change.
195  */
196 int comedi_apply_calibration( comedi_t *dev, unsigned int subdev, unsigned int channel,
197         unsigned int range, unsigned int aref, const char *cal_file_path);
198
199
200 #endif
201
202 #ifdef __cplusplus
203 }
204 #endif
205
206 #endif
207