1 # Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
3 # This file is part of pycomedi.
5 # pycomedi is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 2 of the License, or (at your option) any later
10 # pycomedi is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # pycomedi. If not, see <http://www.gnu.org/licenses/>.
17 "Cython interface to comedilib.h"
19 from _comedi_h cimport *
22 cdef extern from 'comedilib.h':
23 ctypedef struct comedi_t:
26 ctypedef struct comedi_range:
31 comedi_t *comedi_open(char *fn)
32 int comedi_close(comedi_t *it)
36 int comedi_loglevel(int loglevel)
37 void comedi_perror(char *s)
38 char *comedi_strerror(int errnum)
40 int comedi_fileno(comedi_t *it)
44 int comedi_get_n_subdevices(comedi_t *it)
45 # COMEDI_VERSION_CODE handled by device.Device.get_version_code()
46 int comedi_get_version_code(comedi_t *it)
47 char *comedi_get_driver_name(comedi_t *it)
48 char *comedi_get_board_name(comedi_t *it)
49 int comedi_get_read_subdevice(comedi_t *dev)
50 int comedi_get_write_subdevice(comedi_t *dev)
54 int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice)
55 int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd)
56 int comedi_get_subdevice_flags(comedi_t *it,unsigned int subdevice)
57 int comedi_get_n_channels(comedi_t *it,unsigned int subdevice)
58 int comedi_range_is_chan_specific(comedi_t *it,unsigned int subdevice)
59 int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice)
63 lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,
65 int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice,
67 comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,
68 unsigned int chan,unsigned int range)
69 int comedi_find_range(comedi_t *it,unsigned int subd,unsigned int chan,
70 unsigned int unit,double min,double max)
74 int comedi_get_buffer_size(comedi_t *it,unsigned int subdevice)
75 int comedi_get_max_buffer_size(comedi_t *it,unsigned int subdevice)
76 int comedi_set_buffer_size(comedi_t *it,unsigned int subdevice,
81 int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il)
82 int comedi_do_insn(comedi_t *it,comedi_insn *insn)
83 int comedi_lock(comedi_t *it,unsigned int subdevice)
84 int comedi_unlock(comedi_t *it,unsigned int subdevice)
88 int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
89 unsigned int range,unsigned int aref,lsampl_t *data)
90 int comedi_data_read_n(comedi_t *it,unsigned int subd,unsigned int chan,
91 unsigned int range,unsigned int aref,lsampl_t *data, unsigned int n)
92 int comedi_data_read_hint(comedi_t *it,unsigned int subd,unsigned int chan,
93 unsigned int range,unsigned int aref)
94 int comedi_data_read_delayed(comedi_t *it,unsigned int subd,unsigned int chan,
95 unsigned int range,unsigned int aref,lsampl_t *data, unsigned int nano_sec)
96 int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
97 unsigned int range,unsigned int aref,lsampl_t data)
98 int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned int chan,
100 int comedi_dio_get_config(comedi_t *it,unsigned int subd,unsigned int chan,
102 int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan,
104 int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,
106 int comedi_dio_bitfield2(comedi_t *it,unsigned int subd,
107 unsigned int write_mask, unsigned int *bits, unsigned int base_channel)
109 # streaming I/O (commands)
111 int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice,
113 int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice,
114 comedi_cmd *cmd, unsigned chanlist_len, unsigned scan_period_ns)
115 int comedi_cancel(comedi_t *it,unsigned int subdevice)
116 int comedi_command(comedi_t *it,comedi_cmd *cmd)
117 int comedi_command_test(comedi_t *it,comedi_cmd *cmd)
118 int comedi_poll(comedi_t *dev,unsigned int subdevice)
122 int comedi_set_max_buffer_size(comedi_t *it, unsigned int subdev,
123 unsigned int max_size)
124 int comedi_get_buffer_contents(comedi_t *it, unsigned int subdev)
125 int comedi_mark_buffer_read(comedi_t *it, unsigned int subdev,
127 int comedi_mark_buffer_written(comedi_t *it, unsigned int subdev,
129 int comedi_get_buffer_offset(comedi_t *it, unsigned int subdev)
131 # structs and functions used for parsing calibration files
133 ctypedef struct comedi_caldac_t:
134 unsigned int subdevice
138 enum: COMEDI_MAX_NUM_POLYNOMIAL_COEFFICIENTS
140 ctypedef struct comedi_polynomial_t:
141 double coefficients[COMEDI_MAX_NUM_POLYNOMIAL_COEFFICIENTS]
142 double expansion_origin
145 ctypedef struct comedi_softcal_t:
146 comedi_polynomial_t *to_phys
147 comedi_polynomial_t *from_phys
149 enum: CS_MAX_AREFS_LENGTH
151 ctypedef struct comedi_calibration_setting_t:
152 unsigned int subdevice
153 unsigned int *channels
154 unsigned int num_channels
156 unsigned int num_ranges
157 unsigned int arefs[ CS_MAX_AREFS_LENGTH ]
158 unsigned int num_arefs
159 comedi_caldac_t *caldacs
160 unsigned int num_caldacs
161 comedi_softcal_t soft_calibration
163 ctypedef struct comedi_calibration_t:
166 comedi_calibration_setting_t *settings
167 unsigned int num_settings
169 comedi_calibration_t* comedi_parse_calibration_file(
170 char *cal_file_path )
171 int comedi_apply_parsed_calibration( comedi_t *dev, unsigned int subdev,
172 unsigned int channel, unsigned int range, unsigned int aref,
173 comedi_calibration_t *calibration )
174 char* comedi_get_default_calibration_path( comedi_t *dev )
175 void comedi_cleanup_calibration( comedi_calibration_t *calibration )
176 int comedi_apply_calibration( comedi_t *dev, unsigned int subdev,
177 unsigned int channel, unsigned int range, unsigned int aref,
180 # New stuff to provide conversion between integers and physical values that
181 # can support software calibrations.
182 enum comedi_conversion_direction:
185 int comedi_get_softcal_converter(
186 unsigned subdevice, unsigned channel, unsigned range,
187 comedi_conversion_direction direction,
188 comedi_calibration_t *calibration,
189 comedi_polynomial_t *polynomial)
190 int comedi_get_hardcal_converter(
191 comedi_t *dev, unsigned subdevice, unsigned channel, unsigned range,
192 comedi_conversion_direction direction,
193 comedi_polynomial_t *polynomial)
194 double comedi_to_physical(lsampl_t data,
195 comedi_polynomial_t *conversion_polynomial)
196 lsampl_t comedi_from_physical(double data,
197 comedi_polynomial_t *conversion_polynomial)
199 #int comedi_internal_trigger(comedi_t *dev, unsigned subd, unsigned trignum);
200 #/* INSN_CONFIG wrappers */
201 #int comedi_arm(comedi_t *device, unsigned subdevice, unsigned source);
202 #int comedi_reset(comedi_t *device, unsigned subdevice);
203 #int comedi_get_clock_source(comedi_t *device, unsigned subdevice, unsigned channel, unsigned *clock, unsigned *period_ns);
204 #int comedi_get_gate_source(comedi_t *device, unsigned subdevice, unsigned channel,
205 # unsigned gate, unsigned *source);
206 #int comedi_get_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned *routing);
207 #int comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned channel, unsigned mode_bits);
208 #int comedi_set_clock_source(comedi_t *device, unsigned subdevice, unsigned channel, unsigned clock, unsigned period_ns);
209 #int comedi_set_filter(comedi_t *device, unsigned subdevice, unsigned channel, unsigned filter);
210 #int comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned channel, unsigned gate_index, unsigned gate_source);
211 #int comedi_set_other_source(comedi_t *device, unsigned subdevice, unsigned channel,
212 # unsigned other, unsigned source);
213 #int comedi_set_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned routing);
214 #int comedi_get_hardware_buffer_size(comedi_t *device, unsigned subdevice, enum comedi_io_direction direction);