From 87e2e65ce28dc0aee586d9a76535c138c2a3f1fa Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 10 Jul 2019 10:24:17 +0100 Subject: [PATCH] enable debugging --- src/CmdServer.py | 4 ++++ src/CommunicationProcessor.py | 2 +- src/RegisterDatapoint.py | 34 ++++++++++++++++++---------------- src/registers.pkl | Bin 1322 -> 1322 bytes 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/CmdServer.py b/src/CmdServer.py index 31064fa..31b79d4 100644 --- a/src/CmdServer.py +++ b/src/CmdServer.py @@ -232,6 +232,8 @@ class CmdInterpreter(cmd.Cmd): pass elif typ == 'T': value = datetime.timedelta(seconds=float(value)) + elif typ == 'N': + value = None else: 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(" T .. Timedelta, give in seconds") self.__println(" S .. String") + self.__println(" N .. None (Value must be given but is not") + self.__println(" considered)") self.__println(" New value") diff --git a/src/CommunicationProcessor.py b/src/CommunicationProcessor.py index 60d2569..f5bbf54 100644 --- a/src/CommunicationProcessor.py +++ b/src/CommunicationProcessor.py @@ -25,7 +25,7 @@ class CommunicationProcessor(threading.Thread): while True: r = self.queue.get() try: - # print("Dequeued: {0!s}".format(r)) + print("Dequeued: {0!s}".format(r)) r.enqueued = False r.process(client, self.pubQueue) except RegisterDatapoint.DatapointException as e: diff --git a/src/RegisterDatapoint.py b/src/RegisterDatapoint.py index 5418942..6842358 100644 --- a/src/RegisterDatapoint.py +++ b/src/RegisterDatapoint.py @@ -15,18 +15,17 @@ class AbstractModbusDatapoint(object): self.scanRate = scanRate self.type = 'abstract data point' self.enqueued = False + self.lastContact = None if self.scanRate: self.priority = 1 else: self.priority = 0 def __str__(self): - return "{0}, {1}: unit: {2}, address: {3}, count: {4}, scanRate: {5}".format(self.type, - self.label, - self.unit, - self.address, - self.count, - self.scanRate) + return ("{0}, {1}: unit: {2}, address: {3}, count: {4}, scanRate: {5}, " + "enqueued: {6}, lastContact: {7}" + .format(self.type, self.label, self.unit, self.address, self.count, + self.scanRate, self.enqueued, self.lastContact)) def process(self, client): raise NotImplementedError @@ -39,11 +38,13 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint): self.subscribeTopic = subscribeTopic self.feedbackTopic = feedbackTopic self.writeRequestValue = None - self.lastContact = None self.type = 'holding register' 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): successFull = True @@ -61,13 +62,13 @@ class HoldingRegisterDatapoint(AbstractModbusDatapoint): self.writeRequestValue = None else: # perform read operation - # print("Holding register, perform read operation") + print("Holding register, perform read operation") result = client.read_holding_registers(address=self.address, count=self.count, unit=self.unit) if type(result) in [ExceptionResponse, ModbusIOException]: 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))) if successFull: self.lastContact = datetime.datetime.now() @@ -89,10 +90,11 @@ class ReadOnlyDatapoint(AbstractModbusDatapoint): self.updateOnly = updateOnly self.lastValue = None self.publishTopic = publishTopic - self.lastContact = None 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 giveUp = False # perform read operation - # print("Input register, perform read operation") + print("Input register, perform read operation") result = client.read_input_registers(address=self.address, count=self.count, unit=self.unit) @@ -113,7 +115,7 @@ class InputRegisterDatapoint(ReadOnlyDatapoint): raise DatapointException(result) if not self.updateOnly or (result.registers != self.lastValue): 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))) if successFull: @@ -136,7 +138,7 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint): successFull = True giveUp = False # perform read operation - # print("Discrete input, perform read operation") + print("Discrete input, perform read operation") result = client.read_discrete_inputs(address=self.address, count=self.count, unit=self.unit) @@ -144,7 +146,7 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint): raise DatapointException(result) if not self.updateOnly or (result.bits != self.lastValue): 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))) if successFull: diff --git a/src/registers.pkl b/src/registers.pkl index fddd675f2005263a77b785de32bee04b7c3cd51f..5fb85c42f7ab85136e32a9d2a1277ec91892a433 100644 GIT binary patch literal 1322 zcmZ{j%Tv=(6vkWVn<5}0;0t_V@c{z$jnASy0tGLKals;wD>q|E^CdUKu;`4A)6s5S zyY%mIRGX<7lNtUWJ(HxcuTr7AyhVJ+4EX%Qw+5W#cSHlRwDC=P@FXss^ zFhPHDMvH#vE%0dQR}d2Vzmu)0h|1%VFt- zDi))plbP>HEY%9U-e57;{Z-n$(Q<_fv1BO?HG5`Po literal 1322 zcmaiz+fvg&9L7^V)o^E~n0-%2m5!T0FIE*&hFQ z8L_cXXsMz#tE41J@@zxpblocLBVJe9#0s_GQI8r()Rlzz)+?UHaYl|Qaeu#MawO%1 z(k?zqs>`?4l1I_DgLe718XRCdX2mi2K2l<)Lu|7>tz^1vt74lv(n^K~Es+>Z(P=0D2GS z{9%KZxSB$rEXnh-^ciOf`U4|;-=-K)I)$w1CpGGX31Tp?T~ak#!cf2!B|WDk#fWMc z4s~4&%P~)5ex&EC7|F7Doh9l_gvCTgOr&yQ?R!jRA_mEEMlqb z;8G2v1eaMaYZ6}}xXK3DAR7vdHixgVVY$WAj=A|o)72fyY0!YfLg2c#N``6e9@E{ta4=QHbe1K2{1%aN{0MKsuPb%(n2GS_CNmcoaJPng1ouPUm|uqn z1P=vox42T)P(AFytkNTv_e7N`q2izT+x59(&>Gj%M9ii}8@-+{h6bAekJ#|q%7Ky* zhrFZI&{X|>W9#Fh=!|dWNfl2|w=#uiQ7gHQ4?nR`LxEs1YUMe>3(=EVHdkavVW#j> zz^opyru0%3%co0EVQa-{e0RID^fo fbUyRr8@6hAO|Tu6enX&~Bt3(-LVBYiO(*^U1NVi}