コード例 #1
0
 def readDLMSPacket2(self, data, reply):
     if not data:
         return
     notify = GXReplyData()
     reply.error = 0
     eop = 0x7E
     #In network connection terminator is not used.
     if self.client.interfaceType == InterfaceType.WRAPPER and isinstance(
             self.media, GXNet):
         eop = None
     p = ReceiveParameters()
     p.eop = eop
     p.waitTime = self.waitTime
     if eop is None:
         p.Count = 8
     else:
         p.Count = 5
     self.media.eop = eop
     rd = GXByteBuffer()
     with self.media.getSynchronous():
         if not reply.isStreaming():
             self.writeTrace(
                 "TX: " + self.now() + "\t" + GXByteBuffer.hex(data),
                 TraceLevel.VERBOSE)
             print("TX: " + self.now() + "\t" + GXByteBuffer.hex(data))
             self.media.send(data)
         pos = 0
         try:
             while not self.client.getData(rd, reply, notify):
                 if notify.data.size != 0:
                     if not notify.isMoreData():
                         t = GXDLMSTranslator()
                         xml = t.dataToXml(notify.data)
                         print(xml)
                         notify.clear()
                     continue
                 elif not p.eop:
                     p.count = self.client.getFrameSize(rd)
                 while not self.media.receive(p):
                     pos += 1
                     if pos == 3:
                         raise TimeoutException(
                             "Failed to receive reply from the device in given time."
                         )
                     if rd.size == 0:
                         print("Data send failed.  Try to resend " +
                               str(pos) + "/3")
                         self.media.send(data, None)
                 rd.set(p.reply)
                 p.reply = None
         except Exception as e:
             self.writeTrace("RX: " + self.now() + "\t" + str(rd),
                             TraceLevel.ERROR)
             print("RX: " + self.now() + "\t" + str(rd))
             raise e
         self.writeTrace("RX: " + self.now() + "\t" + str(rd),
                         TraceLevel.VERBOSE)
         print("RX: " + self.now() + "\t" + str(rd))
         if reply.error != 0:
             raise GXDLMSException(reply.error)
コード例 #2
0
 def getProfileGenerics(self):
     #pylint: disable=broad-except,too-many-nested-blocks
     cells = []
     profileGenerics = self.client.objects.getObjects(
         ObjectType.PROFILE_GENERIC)
     for it in profileGenerics:
         self.writeTrace(
             "-------- Reading " + str(it.objectType) + " " + str(it.name) +
             " " + it.description, TraceLevel.INFO)
         entriesInUse = self.read(it, 7)
         entries = self.read(it, 8)
         self.writeTrace(
             "Entries: " + str(entriesInUse) + "/" + str(entries),
             TraceLevel.INFO)
         pg = it
         if entriesInUse == 0 or not pg.captureObjects:
             continue
         try:
             cells = self.readRowsByEntry(pg, 1, 1)
             if self.trace > TraceLevel.WARNING:
                 for rows in cells:
                     for cell in rows:
                         if isinstance(cell, bytearray):
                             self.writeTrace(
                                 GXByteBuffer.hex(cell) + " | ",
                                 TraceLevel.INFO)
                         else:
                             self.writeTrace(
                                 str(cell) + " | ", TraceLevel.INFO)
                     self.writeTrace("", TraceLevel.INFO)
         except Exception as ex:
             self.writeTrace("Error! Failed to read first row: " + str(ex),
                             TraceLevel.ERROR)
             if not isinstance(ex, (GXDLMSException, TimeoutException)):
                 traceback.print_exc()
         try:
             start = datetime.datetime.now()
             end = start
             start.replace(hour=0, minute=0, second=0, microsecond=0)
             end.replace(minute=0, second=0, microsecond=0)
             cells = self.readRowsByRange(it, start, end)
             for rows in cells:
                 for cell in rows:
                     if isinstance(cell, bytearray):
                         print(GXByteBuffer.hex(cell) + " | ")
                     else:
                         self.writeTrace(str(cell) + " | ", TraceLevel.INFO)
                 self.writeTrace("", TraceLevel.INFO)
         except Exception as ex:
             self.writeTrace("Error! Failed to read last day: " + str(ex),
                             TraceLevel.ERROR)
コード例 #3
0
 def showValue(self, pos, val):
     if isinstance(val, bytes):
         val = GXByteBuffer.hex(int(val))
     elif isinstance(val, list):
         str_ = ""
         pos2 = 0
         while pos2 != len(val):
             if not str_ == "":
                 str_ += ", "
             tmp = val[pos2]
             if isinstance(tmp, bytes):
                 str_ += GXByteBuffer.hex(int(tmp))
             else:
                 str_ += str(tmp)
             pos2 += 1
         val = str_
     self.writeTrace("Index: " + str(pos) + " Value: " + str(val),
                     TraceLevel.INFO)
コード例 #4
0
 def showValue(self, pos, val):
     if isinstance(val, (bytes, bytearray)):
         val = GXByteBuffer(val)
     elif isinstance(val, list):
         str_ = ""
         for tmp in val:
             if str_:
                 str_ += ", "
             if isinstance(tmp, bytes):
                 str_ += GXByteBuffer.hex(tmp)
             else:
                 str_ += str(tmp)
         val = str_
     self.writeTrace("Index: " + str(pos) + " Value: " + str(val), TraceLevel.INFO)
コード例 #5
0
 def getProfileGenerics(self):
     cells = []
     profileGenerics = self.client.objects.getObjects(
         ObjectType.PROFILE_GENERIC)
     for it in profileGenerics:
         self.writeTrace(
             "-------- Reading " + str(it.objectType) + " " + str(it.name) +
             " " + it.description, TraceLevel.INFO)
         entriesInUse = self.read(it, 7)
         entries = self.read(it, 8)
         self.writeTrace(
             "Entries: " + str(entriesInUse) + "/" + str(entries),
             TraceLevel.INFO)
         pg = it
         if entriesInUse == 0 or len(pg.captureObjects) == 0:
             continue
         try:
             cells = self.readRowsByEntry(pg, 1, 1)
             if self.Trace.value > TraceLevel.WARNING.value:
                 for rows in cells:
                     for cell in rows:
                         if isinstance(cell, bytearray):
                             self.writeTrace(
                                 GXByteBuffer.hex(cell) + " | ",
                                 TraceLevel.INFO)
                         else:
                             self.writeTrace(
                                 str(cell) + " | ", TraceLevel.INFO)
                     self.writeTrace("", TraceLevel.INFO)
         except Exception as ex:
             self.writeTrace(
                 "Error! Failed to read first row: " + ex.getMessage(),
                 TraceLevel.ERROR)
         try:
             start = datetime.datetime.now()
             end = start
             start.replace(hour=0, minute=0, second=0, microsecond=0)
             end.replace(minute=0, second=0, microsecond=0)
             cells = self.readRowsByRange(it, start, end)
             for rows in cells:
                 for cell in rows:
                     if isinstance(cell, bytearray):
                         print(GXByteBuffer.hexToBytes(cell) + " | ")
                     else:
                         self.writeTrace(str(cell) + " | ", TraceLevel.INFO)
                 self.writeTrace("", TraceLevel.INFO)
         except Exception as ex:
             self.writeTrace(
                 "Error! Failed to read last day: " + ex.getMessage(),
                 TraceLevel.ERROR)
コード例 #6
0
 def readDLMSPacket2(self, data, reply):
     if data == None or len(data) == 0:
         return
     notify = GXReplyData()
     reply.error = 0
     succeeded = False
     rd = GXByteBuffer()
     if not reply.isStreaming():
         self.writeTrace(
             "TX: " + self.now() + "\t" + GXByteBuffer.hex(data),
             TraceLevel.VERBOSE)
         self.media.sendall(data)
     msgPos = 0
     count = 100
     pos = 0
     try:
         while not self.client.getData(rd, reply, notify):
             if notify.data.size != 0:
                 if not notify.isMoreData():
                     t = GXDLMSTranslator()
                     xml = t.dataToXml(notify.data)
                     print(xml)
                     notify.clear()
                     msgPos = rd.position
                 continue
             rd.position = msgPos
             rd.set(self.media.recv(100))
         if pos == 3:
             raise ValueError(
                 "Failed to receive reply from the device in given time.")
         if pos != 0:
             print("Data send failed.  Try to resend " + str(pos) + "/3")
         ++pos
     except Exception as e:
         self.writeTrace("RX: " + self.now() + "\t" + rd.__str__(),
                         TraceLevel.ERROR)
         raise e
     self.writeTrace("RX: " + self.now() + "\t" + rd.__str__(),
                     TraceLevel.VERBOSE)
     if reply.error != 0:
         raise GXDLMSException(reply.error)