From 4e0887c6a22a662b6d40181aa1dc31fbf1b14ead Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=89ric=20Piel?= Date: Tue, 16 Oct 2012 12:44:30 +0200 Subject: [PATCH] add support for soft calibration --- pycomedi/channel.pyx | 28 ++++++++++++++++------------ pycomedi/device.pyx | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/pycomedi/channel.pyx b/pycomedi/channel.pyx index 8947415..c7d6cc1 100644 --- a/pycomedi/channel.pyx +++ b/pycomedi/channel.pyx @@ -388,15 +388,14 @@ cdef class AnalogChannel (Channel): `direction` should be a value from `constant.CONVERSION_DIRECTION`. """ cdef _comedilib_h.comedi_polynomial_t poly - #rc = _comedilib_h.comedi_get_softcal_converter( - # self.subdevice.device.device, - # self.subdevice.index, self.index, - # _constant.bitwise_value(self.range), - # _constant.bitwise_value(direction), - # calibration, &poly) - #if rc < 0: - # _error.raise_error(function_name='comedi_get_softcal_converter', - # ret=rc) + rc = _comedilib_h.comedi_get_softcal_converter( + self.subdevice.index, self.index, + _constant.bitwise_value(self.range), + _constant.bitwise_value(direction), + <_comedilib_h.comedi_calibration_t*> calibration, &poly) + if rc < 0: + _error.raise_error(function_name='comedi_get_softcal_converter', + ret=rc) return poly cdef _comedilib_h.comedi_polynomial_t get_hardcal_converter( @@ -421,9 +420,14 @@ cdef class AnalogChannel (Channel): cdef _CalibratedConverter ret flags = self.subdevice.get_flags() if flags.soft_calibrated: - #if calibration is None: - # calibration = self.subdevice.device.parse_calibration() - raise NotImplementedError() + if calibration is None: + calibration = self.subdevice.device.parse_calibration() + to_physical = self.get_softcal_converter( + _constant.CONVERSION_DIRECTION.to_physical, + calibration) + from_physical = self.get_softcal_converter( + _constant.CONVERSION_DIRECTION.from_physical, + calibration) else: to_physical = self.get_hardcal_converter( _constant.CONVERSION_DIRECTION.to_physical) diff --git a/pycomedi/device.pyx b/pycomedi/device.pyx index 62fa73c..3c6b679 100644 --- a/pycomedi/device.pyx +++ b/pycomedi/device.pyx @@ -272,6 +272,20 @@ cdef class Device (object): _error.raise_error( function_name='comedi_get_default_calibration_path') return ret + + def parse_calibration(self, path=None): + """The soft calibration from a file for this device. + + If path is None, the default calibration file is used. + """ + if path is None: + path = self.get_default_calibration_path() + + ret = _comedilib_h.comedi_parse_calibration_file(path) + if ret == NULL: + _error.raise_error( + function_name='comedi_parse_calibration_file') + return ret # extensions to make a more idomatic Python interface -- 2.26.2