From bad4a82292c3fc41357d7c1d7261a77a9e9377e4 Mon Sep 17 00:00:00 2001 From: Nikolay Khabarov <2xl@mail.ru> Date: Sat, 24 Jun 2017 17:49:14 +0300 Subject: [PATCH] raise error if no thermistor connected --- cnc/sensors/thermistor.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cnc/sensors/thermistor.py b/cnc/sensors/thermistor.py index 93e8212..179de43 100644 --- a/cnc/sensors/thermistor.py +++ b/cnc/sensors/thermistor.py @@ -30,7 +30,11 @@ from __future__ import division import math import time -import ads111x as adc +try: + import ads111x as adc +except ImportError: + print("---- ads111x is not detected ----") + adc = None CELSIUS_TO_KELVIN = 273.15 @@ -53,6 +57,8 @@ def get_temperature(channel): :param channel: ads111x channel. :return: temperature in Celsius """ + if adc is None: + raise IOError("ads111x is not connected") v = adc.measure(channel) if v >= Vcc: raise IOError("Thermistor not connected")