Reputation: 167
I have tried to read data from meter by DLMS protocol but only '/?!\r\n'
works another not,
I try to read data such as (1-1.32.7.0 [voltage]) but cannot use it as ASCII,
then I log data from RS485 by paralleled RS485 to USB.
So The code that I have shown below works, but I can't decode anyway.
def readr():
rcx2 = ser.readline()
print(rcx2)
def writex(data):
ser.write(data.encode('raw_unicode_escape'))
readr()
writex('\xa0\x07\x03!\x93\x0f\x01')writex('\xa0+\x03!\x10\xfb\xaf\xe6\xe6\x00`\x1d\xa1\t\x06\x07`\x85t\x05\x08\x01\x01\xbe\x10\x04\x0e\x01\x00\x00\x00\x06_\x1f\x04\x00\x00~\x1f\x04\xb0\xca\xea')
writex('\xa0\x19\x03!2o\xd8\xe6\xe6\x00\xc0\x01\xc1\x00\x01\x01\x00\x00\x00\x00\xff\x02\x00\xc3\xad')
writex('\xa0\x19\x03!T_\xde\xe6\xe6\x00\xc0\x01\xc1\x00\x03\x01\x01 \x07\x00\xff\x02\x00P\x1c')
writex('\xa0\x07\x03!q\x13\xc5')
writex('\xa0\x07\x03!S\x03\xc7')
Upvotes: 0
Views: 8086
Reputation: 286
There is a good library called GuruX you can use it for meter reading.
Here are the links
A sample request is like this.
First you need to install the library:
pip install gurux-common
pip install gurux-serial
pip install gurux-net
pip install gurux-dlms
Refer the documentation for set initial parameters like server address etc.
Now you can read data.
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)
Upvotes: 1
Reputation: 31
There are a number of steps you will need to do before you try to read an attribute. You need to create an Application Association, and before that you need to change the mode of the serial interface to HDLC. You may need security credentials in order to create the Application Association with access to the attribute that you want to read. You can get free excerpts of the Blue Book and Green Book from the DLMS website but you will probably need either the IEC 62056 standards or the full Green Book and Blue Book from the DLMS User Association to get communications established. Technical support is available from the User Association for members via the User Association website.
Upvotes: 1