Hello everyone,
I am currently working on a project where I need to communicate with an electricity meter using the DLMS/COSEM protocol via a Moxa device that acts as a TCP/IP converter. However, I am encountering an issue during the initialization of the DLMS session.
Here is the relevant part of my Python code:
from gurux_dlms.GXDLMSClient import GXDLMSClient
from gurux_net.GXNet import GXNet
from gurux_net.enums.NetworkType import NetworkType
from gurux_common.enums.TraceLevel import TraceLevel
import socket
# IP address and port of the Moxa device
MOXA_IP = "10.206.165.1"
MOXA_PORT = 4012
# Meter addresses
LOGICAL_ADDRESS = 1
HDLC_ADDRESS = 8209
# Set global timeout for sockets
socket.setdefaulttimeout(10)
try:
# Configure TCP connection with Moxa
connection = GXNet(NetworkType.TTCP, MOXA_IP, MOXA_PORT)
# Configure DLMS client
client = GXDLMSClient(
useLogicalNameReferencing=True,
clientAddress=LOGICAL_ADDRESS,
serverAddress=HDLC_ADDRESS
)
client.trace = TraceLevel.VERBOSE
# Open connection
connection.open()
# Initialize DLMS session
snrm_request = client.snrmRequest()
connection.send(snrm_request)
# Receive SNRM response
snrm_response = connection.receive(1024)
print(f"SNRM Response: {snrm_response}")
print(f"Type of SNRM Response: {type(snrm_response)}")
if snrm_response is None:
raise Exception("No response received for SNRM request.")
if isinstance(snrm_response, int):
raise Exception("Received an int value instead of the expected object.")
client.parseUAResponse(snrm_response)
# Send AARQ request
aarq_request = client.aarqRequest()
connection.send(aarq_request)
# Receive AARQ response
aarq_response = connection.receive(1024)
if aarq_response is None:
raise Exception("No response received for AARQ request.")
client.parseAAREResponse(aarq_response)
# Read data from the meter
cosem_object = "1.1.1.8.0.255"
data = client.read(connection, cosem_object)
print(f"Read value: {data}")
except Exception as e:
print(f"Communication error: {e.__class__.__name__} - {e}")
finally:
try:
connection.close()
except Exception as e:
print(f"Error closing connection: {e}")
The issue I am facing is that I receive an AttributeError: 'int' object has no attribute 'eop' when waiting for the SNRM response. The debug output shows that the type of snrm_response is int, which is unexpected.
Here is the debug output:
Creating TCP connection with Moxa...
Connection created: TCP 10.206.165.1:4012
DLMS client configured: <gurux_dlms.GXDLMSClient.GXDLMSClient object at 0x000001A7B52C3040>
Connecting to Moxa at 10.206.165.1:4012...
Connected to Moxa.
Initializing DLMS session...
SNRM Request: bytearray(b'~\xa0\x08\x80#\x03\x93&`~')
Waiting for SNRM response...
Communication error: AttributeError - 'int' object has no attribute 'eop'
Closing connection...
Connection closed.
I would appreciate any insights or suggestions on what might be causing this issue and how to resolve it.
Thank you in advance for your help!
Hi, I believe that theā¦
Hi,
I believe that the reason is in this line:
if isinstance(snrm_response, int):
When you send the SNRM request, you will receive UA response and you need to
use client.parseUAResponse to handle it. Check this:
https://gurux.fi/Gurux.DLMS.Client
BR,
Mikko