Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

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

Breadcrumb

  1. Home
  2. Need Help With Python Lib To Read Voltage and Current From Meter (Code Example Inside)

Need help with Python lib to read voltage and current from meter (Code example inside)

By metricreaders , 7 April, 2023
Forums
Gurux.DLMS

Hello, can anyone help with simple thing for python newbie.
I need to read L1-L3 voltage and L1-L3 current from meter using Gurux.DLMS.Python
lib, but due to lack of experience with python I'm hahinb some problems with it.

My meter is connected via RS485->TCP-IP gateway, it's ok to read data with Gurux Director, also python code can connect to meter (initializeConnection) and exchange packets with (getAssociationView), but have no idea how to get several specific parameters in loop to forward them to another platform to store in db.
here is my current example of code:

I want to get data only from those registers:
1.0.31.7.0.255
1.0.51.7.0.255
1.0.71.7.0.255

1.0.32.7.0.255
1.0.52.7.0.255
1.0.72.7.0.255

class GXSettings:
#
# Constructor.
#
def __init__(self, host, port, serial):
self.media = None
self.trace = TraceLevel.INFO
self.invocationCounter = None
self.client = GXDLMSSecureClient(True)
# Objects to read.
self.readObjects = []
self.outputFile = None

self.media = GXNet(NetworkType.TCP, host, 0)
self.media.port = int(port)
self.client.useLogicalNameReferencing = False
self.client.serverAddress = GXDLMSClient.getServerAddressFromSerialNumber(int(serial))
self.client.gbtWindowSize = int(1)
self.client.hdlcSettings.maxInfoRX = self.client.hdlcSettings.maxInfoTX = int(128)
self.trace = TraceLevel.VERBOSE

def read(self, item, attributeIndex):
data = self.client.read(item, attributeIndex)[0]
reply = GXReplyData()
self.readDataBlock(data, reply)
if item.getDataType(attributeIndex) == DataType.NONE:
item.setDataType(attributeIndex, reply.valueType)
return self.client.updateValue(item, attributeIndex, reply.value)

settings = GXSettings('192.168.100.95',8000,4000001)
reader = GXDLMSReader(settings.client, settings.media, settings.trace, settings.invocationCounter)
settings.media.open()
reader.initializeConnection()
reader.getAssociationView()

class itemdata:
#name=int.from_bytes(_GXCommon.logicalNameToBytes(str('1.0.31.7.0.255')), "big")
name=0xFF00
objectType=ObjectType.REGISTER

item=itemdata()
#attributeIndex=2
#data = settings.client.read(item, attributeIndex)[0]
#data = reader.read(item, 2)[0]
data = settings.client.objects.findBySN(item.name)
reader.showValue('1000', data)

Profile picture for user Kurumi

Kurumi

3 years 2 months ago

Hi, You can give -g argument…

Hi,

You can give -g argument and read those values with command line interface. Try like this:

-g "1.0.31.7.0.255:2"

BR,
Mikko

metricreaders

3 years 2 months ago

Kurumi thanks for idea, that…

Kurumi thanks for idea, that is better, but still not the final idea I'm going to reach. With cli it looks like each time it traverse over all registers tree and receiving register value after about 20-30 seconds, but I want to receive data every 1-2 seconds and then store them in DB for monitoring.
It looks like I need to start process, which will traverse all registers to get required to work info and then using that info it can request several registers every second in loop

metricreaders

3 years 2 months ago

gtw, thanks for prompting…

BTW, thanks for prompting this idea, just found in GXSettings part of code where it puts data from cli and the way it reads it later
now I can combine it in single function, which can retrieve needed values from meter in loop

but it still one thing I'm trying to understand, is it important to call reader.getAssociationView() before retrieving data or it possible to get needed registers once after reader.initializeConnection()
or there is a way to cache results of getAssociationView somewhere

Profile picture for user Kurumi

Kurumi

3 years 1 month ago

Hi, You don't need to read…

Hi,

You don't need to read the association view if you know what you want to read.
You can save the association view using -o argument or add objects manually and ignore reader.getAssociationView().
For example, you can read the clock object like this:

clock = GXDLMSClock("0.0.1.0.0.255")
self.read(clock)

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin