Skip to main content

Gurux DLMS library for Python.

Project description

See An Gurux for an overview.

Join the Gurux Community or follow @Gurux for 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 out Gurux.DLMS.

We are updating documentation on Gurux web page.

Read should read DLMS/COSEM FAQ first to get started. Read Instructions for making your own meter reading application or build own DLMS/COSEM meter/simulator/proxy.

If you have problems you can ask your questions in Gurux Forum.

You can use any connection (TCP, serial, PLC) library you want to. Gurux.DLMS classes only parse the data.

Before start

If you find an issue, please report it here: https://www.gurux.fi/project/issues/gurux.dlms.python

Simple example

First you need to install the library:

pip install gurux_dlms

Before use you must set following device parameters. Parameters are manufacturer spesific.

# First import gurux_dlms. 
from gurux_dlms import *

# All default parameters are given in constructor.
# Is used Logican Name or Short Name referencing.
client = GXDLMSClient(True)

HDLC addressing

Each 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(Serial number)
# Count server address from logican and physical address.
serverAddress = GXDLMSClient.getServerAddress2(logical Address, physical Address, Address size in bytes);

If you are using IEC handshake you must first send identify command and move to mode E.

Support for serial port is added later.

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()
if data:
    self.readDLMSPacket(data, reply)
    self.client.parseUAResponse(reply.data)
    size = self.client.limits.maxInfoTX + 40
    self.replyBuff = bytearray(size)
reply.clear()
self.readDataBlock(self.client.aarqRequest(), reply)
self.client.parseAareResponse(reply.data)
reply.clear()
if self.client.authentication.value > Authentication.LOW.value:
    for it in self.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.
def readDLMSPacket2(self, data, reply):
    if not data:
        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(TranslatorOutputType.SIMPLE_XML)
                    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)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gurux_dlms-1.0.111.tar.gz (275.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gurux_dlms-1.0.111-py3-none-any.whl (525.2 kB view details)

Uploaded Python 3

File details

Details for the file gurux_dlms-1.0.111.tar.gz.

File metadata

  • Download URL: gurux_dlms-1.0.111.tar.gz
  • Upload date:
  • Size: 275.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.9

File hashes

Hashes for gurux_dlms-1.0.111.tar.gz
Algorithm Hash digest
SHA256 8257606946ae85e41a6567eea2d965a8da6c8eaa1b6b53146e9492bada4601b9
MD5 25f182b2ac968ca418026f7c3e87530a
BLAKE2b-256 62d69c383e3ee9e5ad3fc743e6bef9805d39bf321fd6709cf52112a2ad1f7818

See more details on using hashes here.

File details

Details for the file gurux_dlms-1.0.111-py3-none-any.whl.

File metadata

  • Download URL: gurux_dlms-1.0.111-py3-none-any.whl
  • Upload date:
  • Size: 525.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.9

File hashes

Hashes for gurux_dlms-1.0.111-py3-none-any.whl
Algorithm Hash digest
SHA256 e904a0ea33009b7c3af8d9f8272a686cd361ed011f0f934f03a65d61c5103b27
MD5 b9c44daae507546eb3a7a63b71b1ab0a
BLAKE2b-256 cf2130f1b1bee3efac1752529c6f6f3c22771288e3a8d5c9038cca6cae584623

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page