Package: gurux-dlms
See AnGuruxfor an overview.Join the Gurux Community or follow@Guruxfor project updates.gurux_dlms library is a high-performance Python component that helps you to read you DLMS/COSEM compatible electricity, gas or water meters. We have try to make component so easy to use that you do not need understand protocol at all.For more info check outGurux.DLMS.We are updating documentation on Gurux web page.Read should readDLMS/COSEM FAQfirst to get started. Read Instructions for making your ownmeter reading applicationor build own
DLMS/COSEMmeter/simulator/proxy.If you have problems you can ask your questions in GuruxForum.You can use any connection (TCP, serial, PLC) library you want to.
Gurux.DLMS classes only parse the data.Before startIf you find an issue, please report it here:https://www.gurux.fi/project/issues/gurux.dlms.pythonSimple exampleFirst you need to install the library:pipinstallgurux_dlmsBefore use you must set following device parameters.
Parameters are manufacturer spesific.# First import gurux_dlms.fromgurux_dlmsimport*# All default parameters are given in constructor.# Is used Logican Name or Short Name referencing.client=GXDLMSClient(True)HDLC addressingEach meter has own server address. Server address is divided to Logical address and Physical address.
Usually you can use value 1 for meter address. You can count server address from serial number of the meter.
You can use GetServerAddress method for that.# Count server address from serial number.serverAddress=GXDLMSClient.getServerAddressFromSerialNumber(Serialnumber)# Count server address from logican and physical address.serverAddress=GXDLMSClient.getServerAddress2(logicalAddress,physicalAddress,Addresssizeinbytes);If you are using IEC handshake you must first send identify command and move to mode E.Supportforserialportisaddedlater.After you have set parameters you can try to connect to the meter.
First you should send SNRM request and handle UA response.
After that you will send AARQ request and handle AARE response.reply=GXReplyData()data=self.client.snrmRequest()ifdata:self.readDLMSPacket(data,reply)self.client.parseUAResponse(reply.data)size=self.client.hdlc.maxInfoTX+40self.replyBuff=bytearray(size)reply.clear()self.readDataBlock(self.client.aarqRequest(),reply)self.client.parseAareResponse(reply.data)reply.clear()ifself.client.authentication.value>Authentication.LOW.value:foritinself.client.getApplicationAssociationRequest():self.readDLMSPacket(it,reply)self.client.parseApplicationAssociationResponse(reply.data)If parameters are right connection is made.
Next you can read Association view and show all objects that meter can offer.# Read Association View from the meter.reply=GXReplyData()self.readDataBlock(self.client.getObjectsRequest(),reply)objects=self.client.parseObjects(reply.data,True)converter=GXDLMSConverter.GXDLMSConverter()converter.updateOBISCodeInformation(objects)Now you can read wanted objects. After read you must close the connection by sending
disconnecting request.self.readDLMSPacket(self.client.disconnectRequest(),reply)#Close media.defreadDLMSPacket2(self,data,reply):ifnotdata:returnnotify=GXReplyData()reply.error=0succeeded=Falserd=GXByteBuffer()ifnotreply.isStreaming():self.writeTrace("TX: "+self.now()+"\t"+GXByteBuffer.hex(data),TraceLevel.VERBOSE)self.media.sendall(data)msgPos=0count=100pos=0try:whilenotself.client.getData(rd,reply,notify):ifnotify.data.size!=0:ifnotnotify.isMoreData():t=GXDLMSTranslator(TranslatorOutputType.SIMPLE_XML)xml=t.dataToXml(notify.data)print(xml)notify.clear()msgPos=rd.positioncontinuerd.position=msgPosrd.set(self.media.recv(100))ifpos==3:raiseValueError("Failed to receive reply from the device in given time.")ifpos!=0:print("Data send failed.  Try to resend "+str(pos)+"/3")++posexceptExceptionase:self.writeTrace("RX: "+self.now()+"\t"+rd.__str__(),TraceLevel.ERROR)raiseeself.writeTrace("RX: "+self.now()+"\t"+rd.__str__(),TraceLevel.VERBOSE)ifreply.error!=0:raiseGXDLMSException(reply.error)