From: W. Trevor King Date: Sat, 11 May 2013 14:57:57 +0000 (-0400) Subject: surface: Ensure min_position < max_position in _get_min_max_positions X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;ds=inline;p=pypiezo.git surface: Ensure min_position < max_position in _get_min_max_positions 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 ;). --- diff --git a/pypiezo/surface.py b/pypiezo/surface.py index be696f4..632f4ff 100644 --- a/pypiezo/surface.py +++ b/pypiezo/surface.py @@ -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,