Skip to main content

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.hdlc.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)

Release files for gurux-dlms 1.0.203

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gurux-dlms 1.0.203
File Size Uploaded
gurux_dlms-1.0.203.tar.gz 379.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gurux-dlms 1.0.203
File Interpreter ABI Platform
gurux_dlms-1.0.203-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / gurux_dlms-1.0.203.tar.gz

Download URL gurux_dlms-1.0.203.tar.gz
Size 379.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cb5326941c6ce2b1871b91514badc133bce559ad6083b7f87b4cd0ce78181b83
BLAKE2b-256 checksum
How to use checksums
c3107416d61b915c8e31286db9cefd964e6dc8dfadd7f2f0c68111b729da2be0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gurux_dlms-1.0.203-py3-none-any.whl

Download URL gurux_dlms-1.0.203-py3-none-any.whl
Size 702.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7155f473624047ebdff5ee4bca00b04aa83d052c697bb5a0cfb56855ba7969e1
BLAKE2b-256 checksum
How to use checksums
39827452ad80fcf709b5c67fed42a9e022373497130c80731523a8e12ca9a9d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

1.0.203 This release

2 release files

1.0.99

2 release files

1.0.98

2 release files

1.0.97

2 release files

1.0.96

2 release files

1.0.95

2 release files

1.0.93

2 release files

1.0.92

2 release files

1.0.91

2 release files

1.0.90

1 release file

1.0.89

2 release files

1.0.88

2 release files

1.0.87

2 release files

1.0.84

2 release files

1.0.83

2 release files

1.0.81

2 release files

1.0.79

2 release files

1.0.78

2 release files

1.0.77

2 release files

1.0.76

2 release files

1.0.75

2 release files

1.0.74

2 release files

1.0.73

2 release files

1.0.72

2 release files

1.0.71

2 release files

1.0.70

2 release files

1.0.68

2 release files

1.0.67

2 release files

1.0.66

2 release files

1.0.65

2 release files

1.0.64

2 release files

1.0.63

2 release files

1.0.61

2 release files

1.0.60

2 release files

1.0.59

2 release files

1.0.58

2 release files

1.0.57

2 release files

1.0.56

2 release files

1.0.55

2 release files

1.0.54

2 release files

1.0.50

2 release files

1.0.49

2 release files

1.0.48

2 release files

1.0.47

2 release files

1.0.46

2 release files

1.0.44

2 release files

1.0.43

2 release files

1.0.42

2 release files

1.0.41

2 release files

1.0.40

2 release files

1.0.39

2 release files

1.0.38

2 release files

1.0.37

2 release files

1.0.36

2 release files

1.0.33

2 release files

1.0.32

2 release files

1.0.31

2 release files

1.0.30

2 release files

1.0.29

2 release files

1.0.28

2 release files

1.0.27

2 release files

1.0.26

2 release files

1.0.25

2 release files

1.0.24

2 release files

1.0.23

2 release files

1.0.22

2 release files

1.0.18

2 release files

1.0.17

2 release files

1.0.16

2 release files

1.0.14

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page