enable pub and sub at the same holding register

This commit is contained in:
Wolfgang Hottgenroth 2019-07-17 15:36:45 +02:00
parent ab91feafd0
commit 264d1cab14
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
3 changed files with 18 additions and 46 deletions

View File

@ -71,20 +71,6 @@ class CmdInterpreter(cmd.Cmd):
address = parseIntArbitraryBase(address)
count = parseIntArbitraryBase(count)
scanrate = float(scanrate)
if scanrate == 0:
if readTopic:
raise CmdInterpreterException('readTopic must not be set when scanRate is zero')
if not writeTopic:
raise CmdInterpreterException('writeTopic must be set when scanRate is zero')
if not feedbackTopic:
raise CmdInterpreterException('feedbackTopic must be set when scanRate is zero')
else:
if not readTopic:
raise CmdInterpreterException('readTopic must be set when scanRate is zero')
if writeTopic:
raise CmdInterpreterException('writeTopic must not be set when scanRate is zero')
if feedbackTopic:
raise CmdInterpreterException('feedbackTopic must not be set when scanRate is zero')
r = RegisterDatapoint.HoldingRegisterDatapoint(label, unit, address, count, datetime.timedelta(seconds=scanrate), readTopic, writeTopic, feedbackTopic)
self.registers.append(r)
except ValueError as e:
@ -136,8 +122,6 @@ class CmdInterpreter(cmd.Cmd):
address = parseIntArbitraryBase(address)
count = parseIntArbitraryBase(count)
scanrate = float(scanrate)
if scanrate == 0.0:
raise CmdInterpreterException('scanRate must not be zero')
r = RegisterDatapoint.InputRegisterDatapoint(label, unit, address, count, datetime.timedelta(seconds=scanrate), updateOnly, readTopic)
self.registers.append(r)
except ValueError as e:
@ -180,8 +164,6 @@ class CmdInterpreter(cmd.Cmd):
address = parseIntArbitraryBase(address)
count = parseIntArbitraryBase(count)
scanrate = float(scanrate)
if scanrate == 0.0:
raise CmdInterpreterException('scanRate must not be zero')
r = RegisterDatapoint.DiscreteInputDatapoint(label, unit, address, count, datetime.timedelta(seconds=scanrate), updateOnly, readTopic)
self.registers.append(r)
except ValueError as e:

View File

@ -106,7 +106,8 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint):
raise DatapointException("Exception caught when trying to converter modbus data: {0!s}".format(e))
else:
value = result.registers
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(value)))
if self.publishTopic:
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(value)))
self.lastContact = datetime.datetime.now()
def onMessage(self, value):
@ -157,7 +158,8 @@ class InputRegisterDatapoint(ReadOnlyDatapoint):
raise DatapointException("Exception caught when trying to converter modbus data: {0!s}".format(e))
else:
value = result.registers
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(value)))
if self.publishTopic:
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(value)))
self.lastContact = datetime.datetime.now()
@ -186,8 +188,9 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
if not self.updateOnly or (result.bits != self.lastValue):
self.lastValue = result.bits
logger.debug("{0}: {1!s}".format(self.label, result.bits))
for i in range(self.bitCount):
pubQueue.put(MqttProcessor.PublishItem("{0}/{1}".format(self.publishTopic, i), str(result.getBit(i))))
if self.publishTopic:
for i in range(self.bitCount):
pubQueue.put(MqttProcessor.PublishItem("{0}/{1}".format(self.publishTopic, i), str(result.getBit(i))))
self.lastContact = datetime.datetime.now()

View File

@ -41,12 +41,12 @@
"args": {
"address": 40010,
"count": 2,
"feedbackTopic": null,
"feedbackTopic": "FB/Counter1",
"label": "Counter1",
"converter": "uint32",
"publishTopic": "Pub/Counter1",
"scanRate": null,
"subscribeTopic": null,
"subscribeTopic": "Sub/Counter1",
"unit": 4
},
"type": "HoldingRegisterDatapoint"
@ -55,12 +55,12 @@
"args": {
"address": 40012,
"count": 2,
"feedbackTopic": null,
"feedbackTopic": "FB/Counter2",
"label": "Counter2",
"converter": "uint32",
"publishTopic": "Pub/Counter2",
"scanRate": null,
"subscribeTopic": null,
"subscribeTopic": "Pub/Counter2",
"unit": 4
},
"type": "HoldingRegisterDatapoint"
@ -69,26 +69,12 @@
"args": {
"address": 40014,
"count": 2,
"feedbackTopic": null,
"feedbackTopic": "FB/Counter3",
"label": "Counter3",
"converter": "uint32",
"publishTopic": "Pub/Counter3",
"scanRate": null,
"subscribeTopic": null,
"unit": 4
},
"type": "HoldingRegisterDatapoint"
},
{
"args": {
"address": 40016,
"count": 2,
"feedbackTopic": null,
"label": "Counter4",
"converter": "uint32",
"publishTopic": "Pub/Counter4",
"scanRate": 1.0,
"subscribeTopic": null,
"subscribeTopic": "FB/Counter3",
"unit": 4
},
"type": "HoldingRegisterDatapoint"
@ -98,12 +84,13 @@
"address": 40016,
"count": 2,
"feedbackTopic": "FB/Counter4",
"label": "Counter4_W",
"publishTopic": null,
"scanRate": 0.0,
"label": "Counter4",
"converter": "uint32",
"publishTopic": "Pub/Counter4",
"scanRate": 1.0,
"subscribeTopic": "Sub/Counter4",
"unit": 4
},
"type": "HoldingRegisterDatapoint"
}
},
]