u9n / dlms-cosem

A Python library for DLMS/COSEM
Other
80 stars 41 forks source link

HDLC over IP #37

Closed dawidce closed 1 year ago

dawidce commented 3 years ago

Hello,

im trying to connect with the meter via rs converter. It should be 7E1 or 8N1 in config ? Is encryption key and authentication key necessery to read from the meter ?

Krolken commented 3 years ago

Hi.

That depends on the meter. What brand and model are you using.

Newer meters probably have direct HDLC on the optical port, but if you are using an RS converter I am guessing you have fixed contacts that you have connected to.

Is it IDIS conformant? Should be printed on it.

On some meters you need to start with IEC62056-21 and use the Mode E to transfer the meter into the HDLC state.

dawidce commented 3 years ago

Hi,

it's apator norax3. I found this:

http://www.apator.com/uploads/files/Produkty/Liczniki_elektroniczne/norax-1-corax-prim-1/dlmd-cert-1677-apa-norax3-2016-08-18.pdf

so i guess that this meter supports direct hdlc. I can easily do readout with IEC using rs converter set to 7E1. Now i try to implement dlms.

My very first scripts look like this ` from dlms_cosem.clients.dlms_client import DlmsClient from dlms_cosem import enumerations, cosem

read current client invocation counter

with DlmsClient.with_tcp_transport( server_logical_address=1, client_logical_address=16, host="192.168.200.222", port=2222 ).session() as client: data = client.get( cosem.CosemAttribute( interface=enumerations.CosemInterface.DATA, instance=cosem.Obis(0, 0, 0x2B, 1, 0), attribute=2, ) ) ` but i get timeout error

Krolken commented 3 years ago

OK.

So the conformance testing of DLMS doesn't say much. It could still be that the device they tested with had direct HDLC enabled and yours does not.

There can be 2 issues in your setup.

  1. You need to do IEC62056-21 mode E handshake.

You are saying you get an answer on IEC62056-21? What does it answer? You will then probable need to move the device into HDLC/DLMS using IEC62056-21 mode E. I havn't added support for it in the IEC62056-21 library since I haven't had time to play around.

But the protocol is like this.

-> you ask the meter to logon: /?!\n\r <- meter response with id -> you send AckWithOptionSelect(baud_char=my_baud_char, mode_char="2") 2=binary.

Now you should be able to do HDLC communication with the meter.

  1. You are not using HDLC communication profile in your example. You are using TCP communication profile. HDLC is only used over serial lines. When communication with a meter over IP you don't need HDLC to handle the connection.

But your problem is that you are using a TCP/IP converter sending serial data over TCP. and the converting it to serial at the meter. So what you need is a transport that sends HDLC over TCP. The TcpTransport does not do this. I would recommend making a custom transport that takes the HDLC data to be send and sends it over a socket.

Subclass HdlcTransport and override the functions below to use a socket instead:

def _write_bytes(self, to_write: bytes):        
   ...
def _read_frame(self)
   ...
dawidce commented 3 years ago

Hi

which version of HLS authentication is implemented in library ?

Krolken commented 3 years ago

HLS-GMAC. I haven't been able to get hold of any meter that use something else.

Krolken commented 3 years ago

Is everything progressing ok?

Krolken commented 3 years ago

Closing due to inactivity.

dawidce commented 3 years ago

Hello,

sorry for inactivity.

I can not put meter in mode E using IEC62056 library. When I set mod_char to "2" binary the meter responds with standard readout data.

22:19:15,269 INFO: Staring init sequence 22:19:15,270 INFO: Sending request message: RequestMessage(device_address='') 22:19:15,270 DEBUG: Sent b'/?!\r\n' over transport: TcpTransport 22:19:15,270 DEBUG: Resting for 0.25 seconds 22:19:15,521 DEBUG: Received b'/APA5\\2NORAX30\r\n' over transport: TcpTransport 22:19:15,521 INFO: Received identification message: IdentificationMessage(identification='2NORAX30', manufacturer='APA', switchover_baudrate_char='5') 22:19:15,521 INFO: Sending AckOptionsSelect message: AckOptionSelectMessage(baud_char='5', mode_char='2') 22:19:15,521 DEBUG: Sent b'\x06052\r\n' over transport: TcpTransport 22:19:15,521 DEBUG: Resting for 0.25 seconds 22:19:15,772 INFO: Reading standard readout from device. 22:19:17,562 DEBUG: Received b'\x020-0:C.1.0(72432595)\r\n0-0:1.0.0(2021-07-12 22:20:17)\r\n1-0:1.8.1(00000000001.329*kWh)\r\n1-0:1.8.1*101(00000000001.329*kWh)\r\n1-0:1.8.1*102(00000000001.329*kWh)\r\n1-0:1.8.1*103(00000000001.329*kWh)\r\n1-0:1.8.2(00000000000.000*kWh)\r\n1-0:1.8.2*101(00000000000.000*kWh)\r\n1-0:1.8.2*102(00000000000.000*kWh)\r\n1-0:1.8.2*103(00000000000.000*kWh)\r\n1-0:2.8.1(00000000000.501*kWh)\r\n1-0:2.8.1*101(00000000000.501*kWh)\r\n1-0:2.8.1*102(00000000000.501*kWh)\r\n1-0:2.8.1*103(00000000000.501*kWh)\r\n1-0:2.8.2(00000000000.000*kWh)\r\n1-0:2.8.2*101(00000000000.000*kWh)\r\n1-0:2.8.2*102(00000000000.000*kWh)\r\n1-0:2.8.2*103(00000000000.000*kWh)\r\n1-0:1.6.0(00000000000.000*kW)(2021-07-01 00:00:00)\r\n1-0:1.6.0(00000000000.000*kW)(2021-07-01 00:00:00)\r\n1-0:1.6.0*101()()\r\n1-0:1.6.0*102()()\r\n1-0:1.6.0*103()()\r\n1-0:1.6.0*101()()\r\n1-0:1.6.0*102()()\r\n1-0:1.6.0*103()()\r\n1-0:2.6.0(00000000000.000*kW)(2021-07-01 00:00:00)\r\n1-0:2.6.0(00000000000.000*kW)(2021-07-01 00:00:00)\r\n1-0:2.6.0*101()()\r\n1-0:2.6.0*102()()\r\n1-0:2.6.0*103()()\r\n1-0:2.6.0*101()()\r\n1-0:2.6.0*102()()\r\n1-0:2.6.0*103()()\r\n1-0:3.8.1(00000000000.252*kvarh)\r\n1-0:3.8.1*101(00000000000.252*kvarh)\r\n1-0:3.8.1*102(00000000000.252*kvarh)\r\n1-0:3.8.1*103(00000000000.252*kvarh)\r\n1-0:3.8.2(00000000000.000*kvarh)\r\n1-0:3.8.2*101(00000000000.000*kvarh)\r\n1-0:3.8.2*102(00000000000.000*kvarh)\r\n1-0:3.8.2*103(00000000000.000*kvarh)\r\n1-0:4.8.1(00000000000.051*kvarh)\r\n1-0:4.8.1*101(00000000000.051*kvarh)\r\n1-0:4.8.1*102(00000000000.051*kvarh)\r\n1-0:4.8.1*103(00000000000.051*kvarh)\r\n1-0:4.8.2(00000000000.000*kvarh)\r\n1-0:4.8.2*101(00000000000.000*kvarh)\r\n1-0:4.8.2*102(00000000000.000*kvarh)\r\n1-0:4.8.2*103(00000000000.000*kvarh)\r\n!\r\n\x03~' over transport: TcpTransport UPDATE I switched my eth to rs converter to 8N1 config and the meter responded with some chars and exited with tcp error.

22:44:34,542 DEBUG: Connecting to ('192.168.200.222', 2222) 22:44:34,544 INFO: Staring init sequence 22:44:34,544 INFO: Sending request message: RequestMessage(device_address='') 22:44:34,544 DEBUG: Sent b'/?!\r\n' over transport: TcpTransport 22:44:34,544 DEBUG: Resting for 0.25 seconds b'\xaf' b'A' b'P' b'A' b'5' b'\\' b'\xb2' b'N' b'\xcf' b'\xd2' b'A' b'\xd8' b'3' b'0' b'\x8d' b'\n' b'\x82' b'0' b'-' b'0' b':' b'\xc3' b'.' b'\xb1' b'.' b'0' b'(' b'\xb7' b'\xb2' b'\xb4' b'3' b'\xb2' b'5' b'9' b'5' b'\xa9' b'\x8d' b'\n' b'0' b'-' b'0' b':' b'\xb1' b'.' b'0' b'.' b'0' b'(' b'\xb2' b'0' b'\xb2' b'\xb1' b'-' b'0' b'\xb7' b'-' b'\xb1' b'\xb2' b'\xa0' b'\xb2' b'\xb2' b':' b'\xb4' b'5' b':' b'3' b'\xb8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'\xb8' b'.' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'\xb1' b'.' b'3' b'\xb2' b'9' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'\xb1' b'.' b'3' b'\xb2' b'9' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'\xb1' b'.' b'3' b'\xb2' b'9' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'3' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'\xb1' b'.' b'3' b'\xb2' b'9' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'\xb8' b'.' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'3' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'\xb8' b'.' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'5' b'0' b'\xb1' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'5' b'0' b'\xb1' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'5' b'0' b'\xb1' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'3' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'5' b'0' b'\xb1' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'\xb8' b'.' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'3' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'6' b'.' b'0' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xa9' b'(' b'\xb2' b'0' b'\xb2' b'\xb1' b'-' b'0' b'\xb7' b'-' b'0' b'\xb1' b'\xa0' b'0' b'0' b':' b'0' b'0' b':' b'0' b'0' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'6' b'.' b'0' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xa9' b'(' b'\xb2' b'0' b'\xb2' b'\xb1' b'-' b'0' b'\xb7' b'-' b'0' b'\xb1' b'\xa0' b'0' b'0' b':' b'0' b'0' b':' b'0' b'0' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'3' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb1' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'3' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'6' b'.' b'0' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xa9' b'(' b'\xb2' b'0' b'\xb2' b'\xb1' b'-' b'0' b'\xb7' b'-' b'0' b'\xb1' b'\xa0' b'0' b'0' b':' b'0' b'0' b':' b'0' b'0' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'6' b'.' b'0' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xd7' b'\xa9' b'(' b'\xb2' b'0' b'\xb2' b'\xb1' b'-' b'0' b'\xb7' b'-' b'0' b'\xb1' b'\xa0' b'0' b'0' b':' b'0' b'0' b':' b'0' b'0' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'3' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb2' b'.' b'6' b'.' b'0' b'\xaa' b'\xb1' b'0' b'3' b'(' b'\xa9' b'(' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'3' b'.' b'\xb8' b'.' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'\xb2' b'5' b'\xb2' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'3' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'\xb2' b'5' b'\xb2' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'3' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'\xb2' b'5' b'\xb2' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'3' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'3' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'\xb2' b'5' b'\xb2' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'3' b'.' b'\xb8' b'.' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'3' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'3' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'3' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'3' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb4' b'.' b'\xb8' b'.' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'5' b'\xb1' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb4' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'5' b'\xb1' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb4' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'5' b'\xb1' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb4' b'.' b'\xb8' b'.' b'\xb1' b'\xaa' b'\xb1' b'0' b'3' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'5' b'\xb1' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb4' b'.' b'\xb8' b'.' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb4' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'\xb1' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb4' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'\xb2' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'\xb1' b'-' b'0' b':' b'\xb4' b'.' b'\xb8' b'.' b'\xb2' b'\xaa' b'\xb1' b'0' b'3' b'(' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'0' b'.' b'0' b'0' b'0' b'\xaa' b'\xeb' b'\xf6' b'\xe1' b'r' b'\xe8' b'\xa9' b'\x8d' b'\n' b'!' b'\x8d' b'\n' b'\x03' b'\xf0' Traceback (most recent call last): File "/home/pi/.local/lib/python3.7/site-packages/iec62056_21/transports.py", line 354, in _recv b = self.socket.recv(chars) socket.timeout: timed out

Krolken commented 3 years ago

Hi. No problem.

It might be a good idea to switch this issue over to the iec62056-21 repo as it seems to be a feature that is missing there.

The second readout with 8N1 is probably just that the bytes becomes wrong and the library cant find the end byte and stop the readout.

So for setting the meter in mode E.

-> b'/?!\r\n' <- b'/APA5\2NORAX30\r\n' # The \2 indicates that is should support mode E. -> b'\x06052\r\n'. # That is not the correct ack message. It will result in a mode C readout which is what you are seeing.

There is a small note in the README of ice62056-21 that we assume protocol mode "normal". I had to look it up, but to change the meter into mode E we need to use protocol mode "HDLC protocol".

To do that the following needs to be sent.

-> b'/?!\r\n' <- b'/APA5\2NORAX30\r\n' # The \2 indicates that is should support mode E. -> b'\x06252\r\n'. # 2 = hdlc instead of 0 = normal

<- b'\x06252\r\n'. # ack that the meter now is in HDLC mode < switch to 8N1 > -> start sending hdlc frames. The problem is that I hardcoded the protocol mode in the iec62056-21 library to normal mode: ```python class AckOptionSelectMessage(Iec6205621Data): """ Only support protocol mode 0: Normal """ def __init__(self, baud_char, mode_char): self.baud_char = baud_char self.mode_char = mode_char def to_representation(self): return f"{constants.ACK}0{self.baud_char}{self.mode_char}{constants.LINE_END}" ``` So try sending in the correct bytes by hand for now and raise an issue in iec62056-21 to support protocol mode = 2 in AckOptionSelectMessage
svet-b commented 2 years ago

I ended up needing this and implemented the capability in the above PR - figured I'd share if useful. Not sure it's the most beautiful implementation but it seems to do the job.

Unfortunately the meter I'm reading uses short name referencing, so shortly after connecting to it using this HDLC+TCP implementation I hit https://github.com/pwitab/dlms-cosem/issues/50. Therefore I guess it's back to using the Gurux DLMS library - which does support SN, but is otherwise a bit of a mess, so was hoping to avoid...

Krolken commented 1 year ago

I have separated the IO from Transports in the upcoming release. So you can just add a TcpIO or SerialIO for the HDLC-Transport so it is possible to run HDLC over TCP. And it is implemented in a more extensible way. Closing this issue.

Thanks for the PR but I had another implementation in mind.

And for SN support we really need someone to sponsor the development as we have never had the need for it.