handling of bit reads
This commit is contained in:
parent
ac47ff0ebe
commit
0f037b02ea
@ -170,6 +170,7 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
|
|||||||
self.argList = self.argList + ['bitCount']
|
self.argList = self.argList + ['bitCount']
|
||||||
self.type = 'discrete input'
|
self.type = 'discrete input'
|
||||||
self.bitCount = bitCount
|
self.bitCount = bitCount
|
||||||
|
self.lastValues = [None] * self.bitCount
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ("[{0!s}, bitCount: {1}"
|
return ("[{0!s}, bitCount: {1}"
|
||||||
@ -186,11 +187,12 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
|
|||||||
if type(result) in [ExceptionResponse, ModbusIOException]:
|
if type(result) in [ExceptionResponse, ModbusIOException]:
|
||||||
self.errorCount += 1
|
self.errorCount += 1
|
||||||
raise DatapointException(result)
|
raise DatapointException(result)
|
||||||
if not self.updateOnly or (result.bits != self.lastValue):
|
logger.debug("{0}: raw: {1!s}".format(self.label, result.bits))
|
||||||
self.lastValue = result.bits
|
for i in range(self.bitCount):
|
||||||
logger.debug("{0}: {1!s}".format(self.label, result.bits))
|
if not self.updateOnly or (result.getBit(i) != self.lastValues[i]):
|
||||||
if self.publishTopic:
|
self.lastValues[i] = result.getBit(i)
|
||||||
for i in range(self.bitCount):
|
logger.debug("{0}, {1}: changed: {2!s}".format(self.label, i, result.getBit(i)))
|
||||||
|
if self.publishTopic:
|
||||||
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()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user