Added fine calibration. Changed DAQCard-ai-16xe-50 and at-mio-16xe-50
[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 David A. Schleef <ds@stm.lbl.gov>
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
61
62
63 comedi_t *comedi_open(const char *fn);
64 int comedi_close(comedi_t *it);
65
66 /* logging */
67 int comedi_loglevel(int loglevel);
68 void comedi_perror(const char *s);
69 char *comedi_strerror(int errnum);
70 int comedi_errno(void);
71 int comedi_fileno(comedi_t *it);
72
73 /* device queries */
74 int comedi_get_n_subdevices(comedi_t *it);
75 int comedi_get_version_code(comedi_t *it);
76 char *comedi_get_driver_name(comedi_t *it);
77 char *comedi_get_board_name(comedi_t *it);
78
79 /* subdevice queries */
80 int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice);
81 int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd);
82 int comedi_get_subdevice_flags(comedi_t *it,unsigned int subdevice);
83 int comedi_get_n_channels(comedi_t *it,unsigned int subdevice);
84 int comedi_range_is_chan_specific(comedi_t *it,unsigned int subdevice);
85 int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice);
86
87 /* channel queries */
88 lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,
89         unsigned int chan);
90 //int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,
91 //      unsigned int chan);
92 int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice,
93         unsigned int chan);
94 comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,
95         unsigned int chan,unsigned int range);
96 int comedi_find_range(comedi_t *it,unsigned int subd,unsigned int chan,
97         unsigned int unit,double min,double max);
98
99 /* buffer queries */
100 int comedi_get_buffer_size(comedi_t *it,unsigned int subdevice);
101 int comedi_get_max_buffer_size(comedi_t *it,unsigned int subdevice);
102 int comedi_set_buffer_size(comedi_t *it,unsigned int subdevice,
103         unsigned int len);
104
105 /* low-level stuff */
106 #ifdef _COMEDILIB_DEPRECATED
107 int comedi_trigger(comedi_t *it,comedi_trig *trig); /* deprecated */
108 #endif
109 int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il);
110 int comedi_do_insn(comedi_t *it,comedi_insn *insn);
111 int comedi_lock(comedi_t *it,unsigned int subdevice);
112 int comedi_unlock(comedi_t *it,unsigned int subdevice);
113
114 /* physical units */
115 double comedi_to_phys(lsampl_t data,comedi_range *rng,lsampl_t maxdata);
116 lsampl_t comedi_from_phys(double data,comedi_range *rng,lsampl_t maxdata);
117
118 /* syncronous stuff */
119 int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
120         unsigned int range,unsigned int aref,lsampl_t *data);
121 int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
122         unsigned int range,unsigned int aref,lsampl_t data);
123 int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned int chan,
124         unsigned int dir);
125 int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan,
126         unsigned int *bit);
127 int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,
128         unsigned int bit);
129 int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
130         unsigned int write_mask, unsigned int *bits);
131
132 /* slowly varying stuff */
133 int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan);
134 int comedi_sv_update(comedi_sv_t *it);
135 int comedi_sv_measure(comedi_sv_t *it,double *data);
136
137 /* streaming I/O (commands) */
138  
139 int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice,
140         comedi_cmd *cmd);
141 int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice,
142         comedi_cmd *cmd,unsigned int ns);
143 int comedi_cancel(comedi_t *it,unsigned int subdevice);
144 int comedi_command(comedi_t *it,comedi_cmd *cmd);
145 int comedi_command_test(comedi_t *it,comedi_cmd *cmd);
146 int comedi_poll(comedi_t *dev,unsigned int subdevice);
147
148 // changes maximum size (in bytes) of preallocated buffer, requires root priviledge, returns new max size
149 int comedi_set_max_buffer_size(comedi_t *it, unsigned int subdev,
150         unsigned int max_size);
151 // returns number of bytes in buffer waiting to be read by user
152 int comedi_get_buffer_contents(comedi_t *it, unsigned int subdev);
153 // marks 'bytes' number of bytes in buffer as read by user, returns number of bytes left to be read
154 int comedi_mark_buffer_read(comedi_t *it, unsigned int subdev,
155         unsigned int bytes);
156 // returns offset in bytes from beginning of buffer for first unread data point in buffer
157 int comedi_get_buffer_offset(comedi_t *it, unsigned int subdev);
158
159 /* DEPRECATED */
160
161 #ifdef _COMEDILIB_DEPRECATED
162 int comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,
163         unsigned int *trigvar,double *actual_freq);
164 int comedi_timed_1chan(comedi_t *it,unsigned int subdev,unsigned int chan,
165         unsigned int range, unsigned int aref,double freq,
166         unsigned int n_samples,double *data);
167 #endif
168
169
170 /*
171    The following prototypes are ALPHA, indicating that they might change
172    in future releases of comedilib, without regard to backward compatibility.
173  */
174
175 enum comedi_oor_behavior {
176         COMEDI_OOR_NUMBER = 0,
177         COMEDI_OOR_NAN
178 };
179
180 enum comedi_oor_behavior comedi_set_global_oor_behavior(enum comedi_oor_behavior behavior);
181
182
183
184
185 #ifdef __cplusplus
186 }
187 #endif
188
189 #endif
190