From 3040dc9464aaa1fe923b78c3619d08cbdb5bb7b4 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 26 Mar 2012 12:43:58 -0400 Subject: [PATCH] Raise a more useful error message if the Melcor controller is not connected. --- pypid/backend/melcor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pypid/backend/melcor.py b/pypid/backend/melcor.py index c3924d3..eaf317a 100644 --- a/pypid/backend/melcor.py +++ b/pypid/backend/melcor.py @@ -29,6 +29,10 @@ from . import PIDMixin as _PIDMixin from . import TemperatureMixin as _TemperatureMixin +class MelcorError (Exception): + pass + + class Register (object): def __init__(self, name, value, direction='rw', reference=None, help=None): self.name = name @@ -460,6 +464,10 @@ class MelcorBackend (_Backend, _ManualMixin, _PIDMixin, _TemperatureMixin): register.decimal = self._decimal rc = self._client.read_holding_registers( address=register.value, count=1, unit=self._controller) + if rc is None: + raise MelcorError( + ('could not read {} from {}. Is the controller connected?' + ).format(register, self._client)) assert rc.function_code < 0x80 value = rc.registers[0] v = register.decode(value, decimal=self._decimal) -- 2.26.2