DLMS Using Java/Python

802 Views Asked by At

I have an Electric meter which I am currently trying to handshake with, using both Java and Python. It's HDLC Connection mode. When I write to the port according to the DLMS protocol, in Baudrate:300, Bytesize:7,Parity:E, StopBit:1. After sending "/?! \r\n".

I get a response from the

meter="/HXE5\\2HXE12\r\n".

Then I send "ACK 2 5 2 \r\n", but I don't get anything back... Below is the python code. If need be, I could attach the Java Code as well. I just want to get past the Physical Layer now. Thanks

import serial
ser = serial.Serial('COM28', 300, bytesize=7, timeout=1,parity=serial.PARITY_EVEN)
print(ser.name)
ser.write('/?!\r\n'.encode('raw_unicode_escape'))
rcx1 = ser.readline()
ser.write('ACK 2 5 2\r\n'.encode('raw_unicode_escape'))
ser.baudrate=9600
rcx2 = ser.readline()
print(rcx1,'---',rcx2)
ser.close()
2

There are 2 best solutions below

1
On BEST ANSWER

You should ensure 'ACK 2 5 2\r\n' really sent out to the wire before you change the physical baudrate, otherwise the data in sending buffer could be damaged and the meet will not recognize it. Years ago I did the same thing with Python Serial, I remembered I have to do some kind of flushing operation after sent the ACK of the new baud, but I don't remember what exact the function name is. Simply check the PySerial doc should do it. Otherwise you have to do a short sleep after sending to wait the octets going out, but this is not good.

0
On

The issues i was having previously was that, i was sending "ACK" instead of sending 0x06... Thanks