RTXI 1.3
comedilib/include/comedilib.h
Go to the documentation of this file.
00001 /*
00002     include/comedilib.h
00003     header file for the comedi library routines
00004 
00005     COMEDI - Linux Control and Measurement Device Interface
00006     Copyright (C) 1998-2002 David A. Schleef <ds@schleef.org>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU Lesser General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 
00022 */
00023 
00024 
00025 #ifndef _COMEDILIB_H
00026 #define _COMEDILIB_H
00027 
00028 #include <comedi.h>
00029 #include <sys/ioctl.h>
00030 #include <fcntl.h>
00031 #include <stdio.h>
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 /* Macros for swig to %include this file. */
00038 #ifdef SWIG
00039 #define SWIG_OUTPUT(x)  OUTPUT
00040 #define SWIG_INPUT(x)   INPUT
00041 #define SWIG_INOUT(x)   INOUT
00042 #else
00043 #define SWIG_OUTPUT(x)  x
00044 #define SWIG_INPUT(x)   x
00045 #define SWIG_INOUT(x)   x
00046 #endif
00047 
00048 typedef struct comedi_t_struct comedi_t;
00049 
00050 typedef struct{
00051         double min;
00052         double max;
00053         unsigned int unit;
00054 }comedi_range;
00055 
00056 typedef struct comedi_sv_struct{
00057         comedi_t *dev;
00058         unsigned int subdevice;
00059         unsigned int chan;
00060 
00061         /* range policy */
00062         int range;
00063         int aref;
00064 
00065         /* number of measurements to average (for ai) */
00066         int n;
00067 
00068         lsampl_t maxdata;
00069 }comedi_sv_t;
00070 
00071 enum comedi_oor_behavior {
00072         COMEDI_OOR_NUMBER = 0,
00073         COMEDI_OOR_NAN
00074 };
00075 
00076 
00077 
00078 
00079 comedi_t *comedi_open(const char *fn);
00080 int comedi_close(comedi_t *it);
00081 
00082 /* logging */
00083 int comedi_loglevel(int loglevel);
00084 void comedi_perror(const char *s);
00085 const char *comedi_strerror(int errnum);
00086 int comedi_errno(void);
00087 int comedi_fileno(comedi_t *it);
00088 
00089 /* global behavior */
00090 enum comedi_oor_behavior comedi_set_global_oor_behavior(enum comedi_oor_behavior behavior);
00091 
00092 /* device queries */
00093 int comedi_get_n_subdevices(comedi_t *it);
00094 #define COMEDI_VERSION_CODE(a,b,c) (((a)<<16) | ((b)<<8) | (c))
00095 int comedi_get_version_code(comedi_t *it);
00096 const char *comedi_get_driver_name(comedi_t *it);
00097 const char *comedi_get_board_name(comedi_t *it);
00098 int comedi_get_read_subdevice(comedi_t *dev);
00099 int comedi_get_write_subdevice(comedi_t *dev);
00100 
00101 /* subdevice queries */
00102 int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice);
00103 int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd);
00104 int comedi_get_subdevice_flags(comedi_t *it,unsigned int subdevice);
00105 int comedi_get_n_channels(comedi_t *it,unsigned int subdevice);
00106 int comedi_range_is_chan_specific(comedi_t *it,unsigned int subdevice);
00107 int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice);
00108 
00109 /* channel queries */
00110 lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,
00111         unsigned int chan);
00112 int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice,
00113         unsigned int chan);
00114 comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,
00115         unsigned int chan,unsigned int range);
00116 int comedi_find_range(comedi_t *it,unsigned int subd,unsigned int chan,
00117         unsigned int unit,double min,double max);
00118 
00119 /* buffer queries */
00120 int comedi_get_buffer_size(comedi_t *it,unsigned int subdevice);
00121 int comedi_get_max_buffer_size(comedi_t *it,unsigned int subdevice);
00122 int comedi_set_buffer_size(comedi_t *it,unsigned int subdevice,
00123         unsigned int len);
00124 
00125 /* low-level stuff */
00126 #ifdef _COMEDILIB_DEPRECATED
00127 int comedi_trigger(comedi_t *it,comedi_trig *trig); /* deprecated */
00128 #endif
00129 int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il);
00130 int comedi_do_insn(comedi_t *it,comedi_insn *insn);
00131 int comedi_lock(comedi_t *it,unsigned int subdevice);
00132 int comedi_unlock(comedi_t *it,unsigned int subdevice);
00133 
00134 /* physical units */
00135 double comedi_to_phys(lsampl_t data,comedi_range *rng,lsampl_t maxdata);
00136 lsampl_t comedi_from_phys(double data,comedi_range *rng,lsampl_t maxdata);
00137 int comedi_sampl_to_phys(double *dest, int dst_stride, sampl_t *src,
00138         int src_stride, comedi_range *rng, lsampl_t maxdata, int n);
00139 int comedi_sampl_from_phys(sampl_t *dest,int dst_stride,double *src,
00140         int src_stride, comedi_range *rng, lsampl_t maxdata, int n);
00141 
00142 /* syncronous stuff */
00143 int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
00144         unsigned int range,unsigned int aref,lsampl_t *SWIG_OUTPUT(data));
00145 int comedi_data_read_n(comedi_t *it,unsigned int subd,unsigned int chan,
00146         unsigned int range,unsigned int aref,lsampl_t *SWIG_OUTPUT(data), unsigned int n);
00147 int comedi_data_read_hint(comedi_t *it,unsigned int subd,unsigned int chan,
00148         unsigned int range,unsigned int aref);
00149 int comedi_data_read_delayed(comedi_t *it,unsigned int subd,unsigned int chan,
00150         unsigned int range,unsigned int aref,lsampl_t *SWIG_OUTPUT(data), unsigned int nano_sec);
00151 int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
00152         unsigned int range,unsigned int aref,lsampl_t data);
00153 int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned int chan,
00154         unsigned int dir);
00155 int comedi_dio_get_config(comedi_t *it,unsigned int subd,unsigned int chan,
00156         unsigned int *SWIG_OUTPUT(dir));
00157 int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan,
00158         unsigned int *SWIG_OUTPUT(bit));
00159 int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,
00160         unsigned int bit);
00161 int comedi_dio_bitfield2(comedi_t *it,unsigned int subd,
00162         unsigned int write_mask, unsigned int *SWIG_INOUT(bits), unsigned int base_channel);
00163 /* Should be moved to _COMEDILIB_DEPRECATED once bindings for other languages are updated
00164  * to use comedi_dio_bitfield2() instead.*/
00165 int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
00166         unsigned int write_mask, unsigned int *SWIG_INOUT(bits));
00167 
00168 /* slowly varying stuff */
00169 int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan);
00170 int comedi_sv_update(comedi_sv_t *it);
00171 int comedi_sv_measure(comedi_sv_t *it,double *data);
00172 
00173 /* streaming I/O (commands) */
00174 
00175 int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice,
00176         comedi_cmd *SWIG_INOUT(cmd));
00177 int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice,
00178         comedi_cmd *SWIG_INOUT(cmd), unsigned chanlist_len, unsigned scan_period_ns);
00179 int comedi_cancel(comedi_t *it,unsigned int subdevice);
00180 int comedi_command(comedi_t *it,comedi_cmd *cmd);
00181 int comedi_command_test(comedi_t *it,comedi_cmd *SWIG_INOUT(cmd));
00182 int comedi_poll(comedi_t *dev,unsigned int subdevice);
00183 
00184 /* buffer control */
00185 
00186 int comedi_set_max_buffer_size(comedi_t *it, unsigned int subdev,
00187         unsigned int max_size);
00188 int comedi_get_buffer_contents(comedi_t *it, unsigned int subdev);
00189 int comedi_mark_buffer_read(comedi_t *it, unsigned int subdev,
00190         unsigned int bytes);
00191 int comedi_mark_buffer_written(comedi_t *it, unsigned int subdev,
00192         unsigned int bytes);
00193 int comedi_get_buffer_offset(comedi_t *it, unsigned int subdev);
00194 
00195 #ifdef _COMEDILIB_DEPRECATED
00196 /*
00197  * The following functions are deprecated and should not be used.
00198  */
00199 int comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,
00200         unsigned int *trigvar,double *actual_freq);
00201 int comedi_timed_1chan(comedi_t *it,unsigned int subdev,unsigned int chan,
00202         unsigned int range, unsigned int aref,double freq,
00203         unsigned int n_samples,double *data);
00204 int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,
00205         unsigned int chan);
00206 #endif
00207 
00208 
00209 #ifndef _COMEDILIB_STRICT_ABI
00210 /*
00211    The following prototypes are _NOT_ part of the Comedilib ABI, and
00212    may change in future versions without regard to source or binary
00213    compatibility.  In practice, this is a holding place for the next
00214    library ABI version change.
00215  */
00216 /* structs and functions used for parsing calibration files */
00217 typedef struct
00218 {
00219         unsigned int subdevice;
00220         unsigned int channel;
00221         unsigned int value;
00222 } comedi_caldac_t;
00223 #define COMEDI_MAX_NUM_POLYNOMIAL_COEFFICIENTS 4
00224 typedef struct
00225 {
00226         double coefficients[COMEDI_MAX_NUM_POLYNOMIAL_COEFFICIENTS];
00227         double expansion_origin;
00228         unsigned order;
00229 } comedi_polynomial_t;
00230 typedef struct
00231 {
00232         comedi_polynomial_t *to_phys;
00233         comedi_polynomial_t *from_phys;
00234 } comedi_softcal_t;
00235 #define CS_MAX_AREFS_LENGTH 4
00236 typedef struct
00237 {
00238         unsigned int subdevice;
00239         unsigned int *channels;
00240         unsigned int num_channels;
00241         unsigned int *ranges;
00242         unsigned int num_ranges;
00243         unsigned int arefs[ CS_MAX_AREFS_LENGTH ];
00244         unsigned int num_arefs;
00245         comedi_caldac_t *caldacs;
00246         unsigned int num_caldacs;
00247         comedi_softcal_t soft_calibration;
00248 } comedi_calibration_setting_t;
00249 
00250 typedef struct
00251 {
00252         char *driver_name;
00253         char *board_name;
00254         comedi_calibration_setting_t *settings;
00255         unsigned int num_settings;
00256 } comedi_calibration_t;
00257 
00258 comedi_calibration_t* comedi_parse_calibration_file( const char *cal_file_path );
00259 int comedi_apply_parsed_calibration( comedi_t *dev, unsigned int subdev, unsigned int channel,
00260         unsigned int range, unsigned int aref, const comedi_calibration_t *calibration );
00261 char* comedi_get_default_calibration_path( comedi_t *dev );
00262 void comedi_cleanup_calibration( comedi_calibration_t *calibration );
00263 int comedi_apply_calibration( comedi_t *dev, unsigned int subdev, unsigned int channel,
00264         unsigned int range, unsigned int aref, const char *cal_file_path);
00265 
00266 /* New stuff to provide conversion between integers and physical values that
00267 * can support software calibrations. */
00268 enum comedi_conversion_direction
00269 {
00270         COMEDI_TO_PHYSICAL,
00271         COMEDI_FROM_PHYSICAL
00272 };
00273 int comedi_get_softcal_converter(
00274         unsigned subdevice, unsigned channel, unsigned range,
00275         enum comedi_conversion_direction direction,
00276         const comedi_calibration_t *calibration, comedi_polynomial_t* SWIG_OUTPUT(polynomial));
00277 int comedi_get_hardcal_converter(
00278         comedi_t *dev, unsigned subdevice, unsigned channel, unsigned range,
00279         enum comedi_conversion_direction direction, comedi_polynomial_t* SWIG_OUTPUT(polynomial));
00280 double comedi_to_physical(lsampl_t data,
00281         const comedi_polynomial_t *conversion_polynomial);
00282 lsampl_t comedi_from_physical(double data,
00283         const comedi_polynomial_t *conversion_polynomial);
00284 
00285 int comedi_internal_trigger(comedi_t *dev, unsigned subd, unsigned trignum);
00286 /* INSN_CONFIG wrappers */
00287 int comedi_arm(comedi_t *device, unsigned subdevice, unsigned source);
00288 int comedi_reset(comedi_t *device, unsigned subdevice);
00289 int comedi_get_clock_source(comedi_t *device, unsigned subdevice, unsigned *SWIG_OUTPUT(clock), unsigned *SWIG_OUTPUT(period_ns));
00290 int comedi_get_gate_source(comedi_t *device, unsigned subdevice, unsigned channel,
00291         unsigned gate, unsigned *SWIG_OUTPUT(source));
00292 int comedi_get_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned *SWIG_OUTPUT(routing));
00293 int comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned channel, unsigned mode_bits);
00294 int comedi_set_clock_source(comedi_t *device, unsigned subdevice, unsigned clock, unsigned period_ns);
00295 int comedi_set_filter(comedi_t *device, unsigned subdevice, unsigned channel, unsigned filter);
00296 int comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned channel, unsigned gate_index, unsigned gate_source);
00297 int comedi_set_other_source(comedi_t *device, unsigned subdevice, unsigned channel,
00298         unsigned other, unsigned source);
00299 int comedi_set_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned routing);
00300 int comedi_get_hardware_buffer_size(comedi_t *device, unsigned subdevice, enum comedi_io_direction direction);
00301 
00302 #endif
00303 
00304 #ifdef __cplusplus
00305 }
00306 #endif
00307 
00308 #endif
00309 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines