enable debugging
This commit is contained in:
@ -232,6 +232,8 @@ class CmdInterpreter(cmd.Cmd):
|
|||||||
pass
|
pass
|
||||||
elif typ == 'T':
|
elif typ == 'T':
|
||||||
value = datetime.timedelta(seconds=float(value))
|
value = datetime.timedelta(seconds=float(value))
|
||||||
|
elif typ == 'N':
|
||||||
|
value = None
|
||||||
else:
|
else:
|
||||||
raise CmdInterpreterException('unknown type specifier, must be I, F, B, S or T')
|
raise CmdInterpreterException('unknown type specifier, must be I, F, B, S or T')
|
||||||
|
|
||||||
@ -255,6 +257,8 @@ class CmdInterpreter(cmd.Cmd):
|
|||||||
self.__println(" B .. Boolean")
|
self.__println(" B .. Boolean")
|
||||||
self.__println(" T .. Timedelta, give in seconds")
|
self.__println(" T .. Timedelta, give in seconds")
|
||||||
self.__println(" S .. String")
|
self.__println(" S .. String")
|
||||||
|
self.__println(" N .. None (Value must be given but is not")
|
||||||
|
self.__println(" considered)")
|
||||||
self.__println("<value> New value")
|
self.__println("<value> New value")
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class CommunicationProcessor(threading.Thread):
|
|||||||
while True:
|
while True:
|
||||||
r = self.queue.get()
|
r = self.queue.get()
|
||||||
try:
|
try:
|
||||||
# print("Dequeued: {0!s}".format(r))
|
print("Dequeued: {0!s}".format(r))
|
||||||
r.enqueued = False
|
r.enqueued = False
|
||||||
r.process(client, self.pubQueue)
|
r.process(client, self.pubQueue)
|
||||||
except RegisterDatapoint.DatapointException as e:
|
except RegisterDatapoint.DatapointException as e:
|
||||||
|
@ -15,18 +15,17 @@ class AbstractModbusDatapoint(object):
|
|||||||
self.scanRate = scanRate
|
self.scanRate = scanRate
|
||||||
self.type = 'abstract data point'
|
self.type = 'abstract data point'
|
||||||
self.enqueued = False
|
self.enqueued = False
|
||||||
|
self.lastContact = None
|
||||||
if self.scanRate:
|
if self.scanRate:
|
||||||
self.priority = 1
|
self.priority = 1
|
||||||
else:
|
else:
|
||||||
self.priority = 0
|
self.priority = 0
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{0}, {1}: unit: {2}, address: {3}, count: {4}, scanRate: {5}".format(self.type,
|
return ("{0}, {1}: unit: {2}, address: {3}, count: {4}, scanRate: {5}, "
|
||||||
self.label,
|
"enqueued: {6}, lastContact: {7}"
|
||||||
self.unit,
|
.format(self.type, self.label, self.unit, self.address, self.count,
|
||||||
self.address,
|
self.scanRate, self.enqueued, self.lastContact))
|
||||||
self.count,
|
|
||||||
self.scanRate)
|
|
||||||
|
|
||||||
def process(self, client):
|
def process(self, client):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -39,11 +38,13 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint):
|
|||||||
self.subscribeTopic = subscribeTopic
|
self.subscribeTopic = subscribeTopic
|
||||||
self.feedbackTopic = feedbackTopic
|
self.feedbackTopic = feedbackTopic
|
||||||
self.writeRequestValue = None
|
self.writeRequestValue = None
|
||||||
self.lastContact = None
|
|
||||||
self.type = 'holding register'
|
self.type = 'holding register'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "[{0!s}, publishTopic: {1}, subscribeTopic: {2}, feedbackTopic: {3}".format(super().__str__(), self.publishTopic, self.subscribeTopic, self.feedbackTopic)
|
return ("[{0!s}, publishTopic: {1}, subscribeTopic: {2}, feedbackTopic: {3}, "
|
||||||
|
"writeRequestValue: {4!s}"
|
||||||
|
.format(super().__str__(), self.publishTopic, self.subscribeTopic, self.feedbackTopic,
|
||||||
|
self.writeRequestValue))
|
||||||
|
|
||||||
def process(self, client, pubQueue):
|
def process(self, client, pubQueue):
|
||||||
successFull = True
|
successFull = True
|
||||||
@ -61,13 +62,13 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint):
|
|||||||
self.writeRequestValue = None
|
self.writeRequestValue = None
|
||||||
else:
|
else:
|
||||||
# perform read operation
|
# perform read operation
|
||||||
# print("Holding register, perform read operation")
|
print("Holding register, perform read operation")
|
||||||
result = client.read_holding_registers(address=self.address,
|
result = client.read_holding_registers(address=self.address,
|
||||||
count=self.count,
|
count=self.count,
|
||||||
unit=self.unit)
|
unit=self.unit)
|
||||||
if type(result) in [ExceptionResponse, ModbusIOException]:
|
if type(result) in [ExceptionResponse, ModbusIOException]:
|
||||||
raise DatapointException(result)
|
raise DatapointException(result)
|
||||||
# print("{0}: {1!s}".format(self.label, result.registers))
|
print("{0}: {1!s}".format(self.label, result.registers))
|
||||||
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(result.registers)))
|
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(result.registers)))
|
||||||
if successFull:
|
if successFull:
|
||||||
self.lastContact = datetime.datetime.now()
|
self.lastContact = datetime.datetime.now()
|
||||||
@ -89,10 +90,11 @@ class ReadOnlyDatapoint(AbstractModbusDatapoint):
|
|||||||
self.updateOnly = updateOnly
|
self.updateOnly = updateOnly
|
||||||
self.lastValue = None
|
self.lastValue = None
|
||||||
self.publishTopic = publishTopic
|
self.publishTopic = publishTopic
|
||||||
self.lastContact = None
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "[{0!s}, updateOnly: {1}, publishTopic: {2}".format(super().__str__(), self.updateOnly, self.publishTopic)
|
return ("[{0!s}, updateOnly: {1}, publishTopic: {2}, lastValue: {3!s}"
|
||||||
|
.format(super().__str__(), self.updateOnly, self.publishTopic,
|
||||||
|
self.lastValue))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -105,7 +107,7 @@ class InputRegisterDatapoint(ReadOnlyDatapoint):
|
|||||||
successFull = True
|
successFull = True
|
||||||
giveUp = False
|
giveUp = False
|
||||||
# perform read operation
|
# perform read operation
|
||||||
# print("Input register, perform read operation")
|
print("Input register, perform read operation")
|
||||||
result = client.read_input_registers(address=self.address,
|
result = client.read_input_registers(address=self.address,
|
||||||
count=self.count,
|
count=self.count,
|
||||||
unit=self.unit)
|
unit=self.unit)
|
||||||
@ -113,7 +115,7 @@ class InputRegisterDatapoint(ReadOnlyDatapoint):
|
|||||||
raise DatapointException(result)
|
raise DatapointException(result)
|
||||||
if not self.updateOnly or (result.registers != self.lastValue):
|
if not self.updateOnly or (result.registers != self.lastValue):
|
||||||
self.lastValue = result.registers
|
self.lastValue = result.registers
|
||||||
# print("{0}: {1!s}".format(self.label, result.registers))
|
print("{0}: {1!s}".format(self.label, result.registers))
|
||||||
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(result.registers)))
|
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(result.registers)))
|
||||||
|
|
||||||
if successFull:
|
if successFull:
|
||||||
@ -136,7 +138,7 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
|
|||||||
successFull = True
|
successFull = True
|
||||||
giveUp = False
|
giveUp = False
|
||||||
# perform read operation
|
# perform read operation
|
||||||
# print("Discrete input, perform read operation")
|
print("Discrete input, perform read operation")
|
||||||
result = client.read_discrete_inputs(address=self.address,
|
result = client.read_discrete_inputs(address=self.address,
|
||||||
count=self.count,
|
count=self.count,
|
||||||
unit=self.unit)
|
unit=self.unit)
|
||||||
@ -144,7 +146,7 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
|
|||||||
raise DatapointException(result)
|
raise DatapointException(result)
|
||||||
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
|
||||||
# print("{0}: {1!s}".format(self.label, result.bits))
|
print("{0}: {1!s}".format(self.label, result.bits))
|
||||||
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(result.bits)))
|
pubQueue.put(MqttProcessor.PublishItem(self.publishTopic, str(result.bits)))
|
||||||
|
|
||||||
if successFull:
|
if successFull:
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user