From 435f2cfc70ff9eb3ccd473db9cd697238c5a68c5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 11 May 2013 10:57:57 -0400 Subject: [PATCH] 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 ;). --- pypiezo/surface.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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, -- 2.26.2