add support for soft calibration
[pycomedi.git] / pycomedi / channel.pyx
index 8947415f493792860bb4cbe9cf0c86c7c5278663..c7d6cc178cdceb1a16819b8cd6dcc3971c395393 100644 (file)
@@ -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)