introduce lastException and lastReadValue for communication with CmdServer
This commit is contained in:
parent
b6077b0ec8
commit
b97b849bfa
@ -59,6 +59,8 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint):
|
|||||||
self.feedbackTopic = feedbackTopic
|
self.feedbackTopic = feedbackTopic
|
||||||
self.writeRequestValue = None
|
self.writeRequestValue = None
|
||||||
self.type = 'holding register'
|
self.type = 'holding register'
|
||||||
|
self.lastException = None
|
||||||
|
self.lastReadValue = None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ("[{0!s}, publishTopic: {1}, subscribeTopic: {2}, feedbackTopic: {3}, "
|
return ("[{0!s}, publishTopic: {1}, subscribeTopic: {2}, feedbackTopic: {3}, "
|
||||||
@ -81,6 +83,7 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint):
|
|||||||
else:
|
else:
|
||||||
values = [int(self.writeRequestValue)]
|
values = [int(self.writeRequestValue)]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
self.lastException = e
|
||||||
raise DatapointException("Exception caught when trying to converter modbus data: {0!s}".format(e))
|
raise DatapointException("Exception caught when trying to converter modbus data: {0!s}".format(e))
|
||||||
result = client.write_registers(address=self.address,
|
result = client.write_registers(address=self.address,
|
||||||
unit=self.unit,
|
unit=self.unit,
|
||||||
@ -96,6 +99,7 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint):
|
|||||||
unit=self.unit)
|
unit=self.unit)
|
||||||
if type(result) in [ExceptionResponse, ModbusIOException]:
|
if type(result) in [ExceptionResponse, ModbusIOException]:
|
||||||
self.errorCount += 1
|
self.errorCount += 1
|
||||||
|
self.lastException = result
|
||||||
raise DatapointException(result)
|
raise DatapointException(result)
|
||||||
logger.debug("{0}: {1!s}".format(self.label, result.registers))
|
logger.debug("{0}: {1!s}".format(self.label, result.registers))
|
||||||
value = None
|
value = None
|
||||||
@ -106,7 +110,9 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint):
|
|||||||
else:
|
else:
|
||||||
value = result.registers
|
value = result.registers
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
self.lastException = e
|
||||||
raise DatapointException("Exception caught when trying to converter modbus data: {0!s}".format(e))
|
raise DatapointException("Exception caught when trying to converter modbus data: {0!s}".format(e))
|
||||||
|
self.lastReadValue = value
|
||||||
if self.publishTopic:
|
if self.publishTopic:
|
||||||
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(value)))
|
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(value)))
|
||||||
self.lastContact = datetime.datetime.now()
|
self.lastContact = datetime.datetime.now()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user