From b97b849bfa33e110f41f31d44e65ebbae60860ae Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sun, 28 Jul 2019 01:14:21 +0200 Subject: [PATCH] introduce lastException and lastReadValue for communication with CmdServer --- src/RegisterDatapoint.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/RegisterDatapoint.py b/src/RegisterDatapoint.py index 4a72a7b..9621a12 100644 --- a/src/RegisterDatapoint.py +++ b/src/RegisterDatapoint.py @@ -59,6 +59,8 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint): self.feedbackTopic = feedbackTopic self.writeRequestValue = None self.type = 'holding register' + self.lastException = None + self.lastReadValue = None def __str__(self): return ("[{0!s}, publishTopic: {1}, subscribeTopic: {2}, feedbackTopic: {3}, " @@ -81,6 +83,7 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint): else: values = [int(self.writeRequestValue)] except Exception as e: + self.lastException = e raise DatapointException("Exception caught when trying to converter modbus data: {0!s}".format(e)) result = client.write_registers(address=self.address, unit=self.unit, @@ -96,6 +99,7 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint): unit=self.unit) if type(result) in [ExceptionResponse, ModbusIOException]: self.errorCount += 1 + self.lastException = result raise DatapointException(result) logger.debug("{0}: {1!s}".format(self.label, result.registers)) value = None @@ -106,7 +110,9 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint): else: value = result.registers except Exception as e: + self.lastException = e raise DatapointException("Exception caught when trying to converter modbus data: {0!s}".format(e)) + self.lastReadValue = value if self.publishTopic: pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(value))) self.lastContact = datetime.datetime.now()