enable pub and sub at the same holding register
This commit is contained in:
parent
ab91feafd0
commit
264d1cab14
@ -71,20 +71,6 @@ class CmdInterpreter(cmd.Cmd):
|
|||||||
address = parseIntArbitraryBase(address)
|
address = parseIntArbitraryBase(address)
|
||||||
count = parseIntArbitraryBase(count)
|
count = parseIntArbitraryBase(count)
|
||||||
scanrate = float(scanrate)
|
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)
|
r = RegisterDatapoint.HoldingRegisterDatapoint(label, unit, address, count, datetime.timedelta(seconds=scanrate), readTopic, writeTopic, feedbackTopic)
|
||||||
self.registers.append(r)
|
self.registers.append(r)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
@ -136,8 +122,6 @@ class CmdInterpreter(cmd.Cmd):
|
|||||||
address = parseIntArbitraryBase(address)
|
address = parseIntArbitraryBase(address)
|
||||||
count = parseIntArbitraryBase(count)
|
count = parseIntArbitraryBase(count)
|
||||||
scanrate = float(scanrate)
|
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)
|
r = RegisterDatapoint.InputRegisterDatapoint(label, unit, address, count, datetime.timedelta(seconds=scanrate), updateOnly, readTopic)
|
||||||
self.registers.append(r)
|
self.registers.append(r)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
@ -180,8 +164,6 @@ class CmdInterpreter(cmd.Cmd):
|
|||||||
address = parseIntArbitraryBase(address)
|
address = parseIntArbitraryBase(address)
|
||||||
count = parseIntArbitraryBase(count)
|
count = parseIntArbitraryBase(count)
|
||||||
scanrate = float(scanrate)
|
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)
|
r = RegisterDatapoint.DiscreteInputDatapoint(label, unit, address, count, datetime.timedelta(seconds=scanrate), updateOnly, readTopic)
|
||||||
self.registers.append(r)
|
self.registers.append(r)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
@ -106,6 +106,7 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint):
|
|||||||
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))
|
||||||
else:
|
else:
|
||||||
value = result.registers
|
value = result.registers
|
||||||
|
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()
|
||||||
|
|
||||||
@ -157,6 +158,7 @@ class InputRegisterDatapoint(ReadOnlyDatapoint):
|
|||||||
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))
|
||||||
else:
|
else:
|
||||||
value = result.registers
|
value = result.registers
|
||||||
|
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()
|
||||||
|
|
||||||
@ -186,6 +188,7 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
|
|||||||
if not self.updateOnly or (result.bits != self.lastValue):
|
if not self.updateOnly or (result.bits != self.lastValue):
|
||||||
self.lastValue = result.bits
|
self.lastValue = result.bits
|
||||||
logger.debug("{0}: {1!s}".format(self.label, result.bits))
|
logger.debug("{0}: {1!s}".format(self.label, result.bits))
|
||||||
|
if self.publishTopic:
|
||||||
for i in range(self.bitCount):
|
for i in range(self.bitCount):
|
||||||
pubQueue.put(MqttProcessor.PublishItem("{0}/{1}".format(self.publishTopic, i), str(result.getBit(i))))
|
pubQueue.put(MqttProcessor.PublishItem("{0}/{1}".format(self.publishTopic, i), str(result.getBit(i))))
|
||||||
self.lastContact = datetime.datetime.now()
|
self.lastContact = datetime.datetime.now()
|
||||||
|
@ -41,12 +41,12 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"address": 40010,
|
"address": 40010,
|
||||||
"count": 2,
|
"count": 2,
|
||||||
"feedbackTopic": null,
|
"feedbackTopic": "FB/Counter1",
|
||||||
"label": "Counter1",
|
"label": "Counter1",
|
||||||
"converter": "uint32",
|
"converter": "uint32",
|
||||||
"publishTopic": "Pub/Counter1",
|
"publishTopic": "Pub/Counter1",
|
||||||
"scanRate": null,
|
"scanRate": null,
|
||||||
"subscribeTopic": null,
|
"subscribeTopic": "Sub/Counter1",
|
||||||
"unit": 4
|
"unit": 4
|
||||||
},
|
},
|
||||||
"type": "HoldingRegisterDatapoint"
|
"type": "HoldingRegisterDatapoint"
|
||||||
@ -55,12 +55,12 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"address": 40012,
|
"address": 40012,
|
||||||
"count": 2,
|
"count": 2,
|
||||||
"feedbackTopic": null,
|
"feedbackTopic": "FB/Counter2",
|
||||||
"label": "Counter2",
|
"label": "Counter2",
|
||||||
"converter": "uint32",
|
"converter": "uint32",
|
||||||
"publishTopic": "Pub/Counter2",
|
"publishTopic": "Pub/Counter2",
|
||||||
"scanRate": null,
|
"scanRate": null,
|
||||||
"subscribeTopic": null,
|
"subscribeTopic": "Pub/Counter2",
|
||||||
"unit": 4
|
"unit": 4
|
||||||
},
|
},
|
||||||
"type": "HoldingRegisterDatapoint"
|
"type": "HoldingRegisterDatapoint"
|
||||||
@ -69,26 +69,12 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"address": 40014,
|
"address": 40014,
|
||||||
"count": 2,
|
"count": 2,
|
||||||
"feedbackTopic": null,
|
"feedbackTopic": "FB/Counter3",
|
||||||
"label": "Counter3",
|
"label": "Counter3",
|
||||||
"converter": "uint32",
|
"converter": "uint32",
|
||||||
"publishTopic": "Pub/Counter3",
|
"publishTopic": "Pub/Counter3",
|
||||||
"scanRate": null,
|
"scanRate": null,
|
||||||
"subscribeTopic": null,
|
"subscribeTopic": "FB/Counter3",
|
||||||
"unit": 4
|
|
||||||
},
|
|
||||||
"type": "HoldingRegisterDatapoint"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"args": {
|
|
||||||
"address": 40016,
|
|
||||||
"count": 2,
|
|
||||||
"feedbackTopic": null,
|
|
||||||
"label": "Counter4",
|
|
||||||
"converter": "uint32",
|
|
||||||
"publishTopic": "Pub/Counter4",
|
|
||||||
"scanRate": 1.0,
|
|
||||||
"subscribeTopic": null,
|
|
||||||
"unit": 4
|
"unit": 4
|
||||||
},
|
},
|
||||||
"type": "HoldingRegisterDatapoint"
|
"type": "HoldingRegisterDatapoint"
|
||||||
@ -98,12 +84,13 @@
|
|||||||
"address": 40016,
|
"address": 40016,
|
||||||
"count": 2,
|
"count": 2,
|
||||||
"feedbackTopic": "FB/Counter4",
|
"feedbackTopic": "FB/Counter4",
|
||||||
"label": "Counter4_W",
|
"label": "Counter4",
|
||||||
"publishTopic": null,
|
"converter": "uint32",
|
||||||
"scanRate": 0.0,
|
"publishTopic": "Pub/Counter4",
|
||||||
|
"scanRate": 1.0,
|
||||||
"subscribeTopic": "Sub/Counter4",
|
"subscribeTopic": "Sub/Counter4",
|
||||||
"unit": 4
|
"unit": 4
|
||||||
},
|
},
|
||||||
"type": "HoldingRegisterDatapoint"
|
"type": "HoldingRegisterDatapoint"
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user