surface: Ensure min_position < max_position in _get_min_max_positions master
authorW. Trevor King <wking@tremily.us>
Sat, 11 May 2013 14:57:57 +0000 (10:57 -0400)
committerW. Trevor King <wking@tremily.us>
Sat, 11 May 2013 14:57:57 +0000 (10:57 -0400)
Otherwise log the configuration and raise a ValueError.

It's unlikely that a user misconfigures their ranges, but it is
possible.  It is also possible that a bug in pycomedi---like the one
fixed by 27562b0 (channel: Fix to-physical setup in
AnalogChannel._get_converter, 2013-01-17)---leads to a broken
inverse-conversion-coefficients configuration.  That bug is now fixed,
but if it happened once, it might happen again ;).

pypiezo/surface.py

index be696f4fbde4405ccd825ecac34ff5ac670b5ca8..632f4ffd3c5bce4ace8944a785190f13361c3be4 100644 (file)
@@ -85,6 +85,15 @@ def _get_min_max_positions(piezo, axis_name, min_position=None,
         max_position = _base.convert_volts_to_bits(
             output_axis.config['channel'],
             output_axis.config['maximum'])
+    if min_position >= max_position:
+        for k,v in output_axis.config['channel'].items():
+            _LOG.error((k,v))
+        raise ValueError(
+            ('invalid range {} - {} for {} axis {} (configured with {} - {})'
+             ).format(
+                min_position, max_position, piezo.config.get('name', piezo),
+                axis_name, output_axis.config['minimum'],
+                output_axis.config['maximum']))
     return (min_position, max_position)
 
 def get_surface_position_data(piezo, axis_name, max_deflection, steps=2000,