Skip to main content
Home
for DLMS smart meters

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Python Example

Python example

By ksk, 9 September, 2025
Forums
Gurux.DLMS

This is my first time trying to get data on DLMS in python.

GXDLMSDirector connects everything, everything is visible.
I tried the example from Gurux.DLMS.Client.Example.python/main.py and it also reads everything, but it reads all the parameters.

Is there an example of code where I could read the list of OBIS codes that I need, because everything I tried didn't work for me?

Profile picture for user Kurumi

Kurumi

1 month 4 weeks ago

Hi, When you read the…

Hi,

When you read the association, it will describe features the meter can offer.

You need to check what you want to read from the meter and modify the client example for your needs.

BR,
Mikko

ksk

1 month 3 weeks ago

I'm using the example script…

I'm using the example script, which reads all codes and values ​​from the counter using the reader.readAll() function. It works. One caveat is that when using the '-o output.xml' flag, the configuration isn't saved to the file, and everything is read anew each time, but that's a different issue. GXDLMSDirector also reads everything.

But I want to get the values ​​of a specific OBIS code, say "0.0.1.0.0.255." To do this, I use:

reader.readAll()

This code (from examples here on the forum):

obj = GXDLMSClock("0.0.1.0.0.255")
reader.read(obj, 2)

But I get an error:

Data send failed. Try to resend 1/3
Data send failed. Try to resend 2/3
RX: 13:22:33
Traceback (most recent call last):
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\main2.py", line 120, in main
reader.read(obj, 2)
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\GXDLMSReader.py", line 409, in read
self.readDataBlock(data, reply)
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\GXDLMSReader.py", line 235, in readDataBlock
self.readDLMSPacket(data, reply)
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\GXDLMSReader.py", line 164, in readDLMSPacket
self.readDLMSPacket2(data, reply)
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\GXDLMSReader.py", line 222, in readDLMSPacket2
raise e
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\GXDLMSReader.py", line 213, in readDLMSPacket2
raise TimeoutException(
gurux_common.TimeoutException.TimeoutException: Failed to receive reply from the device in given time.
Ended. Press any key to continue.

ksk

1 month 3 weeks ago

If I run it with the command…

If I run it with the command:
py main.py -S COM2:9600:8None1 -i HdlcWithModeE -c 3 -s 22922 -a Low -P ABCDEFGH -g "0.0.1.0.0.255:2"

I get the error:
C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\main.py:52: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
gurux_dlms version: 1.0.191
gurux_net version: 1.0.23
gurux_serial version: 1.0.21
['main.py', '-S', 'COM2:9600:8None1', '-i', 'HdlcWithModeE', '-c', '3', '-s', '22922', '-a', 'Low', '-P', 'ABCDEFGH', '-g', '0.0.1.0.0.255:2']
Authentication: 1
ClientAddress: 0x3
ServerAddress: 0x598a
Standard: 0
Traceback (most recent call last):
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\main.py", line 111, in main
reader.initializeConnection()
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\GXDLMSReader.py", line 382, in initializeConnection
self.initializeOpticalHead()
File "C:\projects\server\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\GXDLMSReader.py", line 254, in initializeOpticalHead
raise Exception("Failed to received reply from the media.")
Exception: Failed to received reply from the media.
Ended. Press any key to continue.

ksk

1 month 3 weeks ago

Sorry, but the script ended…

Sorry, but the script ended up with the following parameters:
py main.py -S COM2:9600:8None1 -c 3 -s 22922 -a Low -P ABCDEFGH -g "0.0.1.0.0.255:2"
It worked. I spent a long time reading it each time, but I added the -o flag with the .xml file and it worked perfectly.

Profile picture for user Kurumi

Kurumi

1 month 2 weeks ago

Hi, The reason for this is…

Hi,
The reason for this is that your meter doesn't support Mode E when you are using the optical probe. The meter is using only HDLC.

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 10/29/2025 - 08:51
    gurux.dlms.c 9.0.2510.2901
  • Thu, 10/16/2025 - 09:59
    gurux.dlms.java 4.0.83
  • Wed, 10/08/2025 - 10:21
    gurux.dlms.c 9.0.2510.0801
  • Fri, 09/26/2025 - 10:02
    gurux.dlms.cpp 9.0.2509.2601
  • Fri, 09/26/2025 - 09:45
    gurux.dlms.c 9.0.2509.2601

New forum topics

  • Guidance on using the source codes
  • How to get/convert user readable format data from readRowsByRange
  • Insufficient memory to continue the execution of the program.
  • The client instance code failed to connect to the electricity meter for authentication
  • Unable to Release Request when closing connection with meter.
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin