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