Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Node
  3. Can't Able To Read Data From Method ReadDLMSPacket(byte[] Data, GXReplyData Reply)

Can't able to Read Data from method readDLMSPacket(byte[] data, GXReplyData reply)

By Akash , 12 April, 2024
Forums
Gurux DLMS for Android

first time i can able to read data second time if i want to read data i am facing issue

Some times i am getting data.length 0 , and some time if data length grater then 0 also i am not getting data Exception as

java.lang.RuntimeException: java.lang.IllegalArgumentException: Data send failed.

java.lang.NullPointerException: Attempt to get length of null array

public void readDLMSPacket(byte[] data, GXReplyData reply) throws Exception {

System.out.println("==data"+data.length);
if (data == null || data.length == 0) {
return;
}

IGXMedia media = mDevice.getMedia();
reply.setError((short) 0);
Object eop = (byte) 0x7E;
Integer pos = 0;
boolean succeeded = false;
ReceiveParameters<byte[]> p =
new ReceiveParameters<byte[]>(byte[].class);
p.setEop(eop);
p.setCount(5);
p.setWaitTime(mDevice.getWaitTime() * 1000);
synchronized (media.getSynchronous()) {
while (!succeeded) {
writeTrace("<- " + now() + "\t" + GXCommon.bytesToHex(data));
System.out.print(now() + "Tx:" + "\t" + GXCommon.bytesToHex(data));
System.out.println();
media.send(data, null);
if (p.getEop() == null) {
p.setCount(1);
}
succeeded = media.receive(p);

if (!succeeded) {
// Try to read again...
if (pos++ == 3) {
throw new RuntimeException("Failed to receive reply from the device in given time.");
}
AlertClass.alert_("Data send failed. Try to resend " + pos.toString() + "/3",getApplicationContext());
System.out.println("Data send failed. Try to resend " + pos.toString() + "/3");
}
}
// Loop until whole DLMS packet is received.
try {
while (!mClient.getData(p.getReply(), reply)) {
if (p.getEop() == null) {
p.setCount(1);
}
if (!media.receive(p)) {
// If echo.
if (reply.isEcho()) {
media.send(data, null);
}
// Try to read again...
if (++pos == 3) {
throw new Exception(
"Failed to receive reply from the device in given time.");
}
AlertClass.alert_("Data send failed3. Try to resend" + pos.toString() + "/3",getApplicationContext());

System.out.println("Data send failed. Try to resend " + pos.toString() + "/3");
}
}
} catch (Exception e) {
System.out.println("readDLMSPacket_exeption");
Log.d("==data", String.valueOf( now() + "\t" + GXCommon.bytesToHex(p.getReply())));
writeTrace("-> " + now() + "\t" + GXCommon.bytesToHex(p.getReply()));
System.out.print(now()+"RxE:" + "\t" + GXCommon.bytesToHex(p.getReply()));
System.out.println();
throw e;
}

}
writeTrace("-> " + now() + "\t" + GXCommon.bytesToHex(p.getReply()));
System.out.print(now()+"Rx:" + "\t" + GXCommon.bytesToHex(p.getReply()));
System.out.println();

if (reply.getError() != 0) {
if (reply.getError() == ErrorCode.REJECTED.getValue()) {
Thread.sleep(1000);
readDLMSPacket(data, reply);
} else {
System.out.println("Data send failed. Try to resend once ");
// throw new GXDLMSException(reply.getError());
}
}
// readDLMSPacket(mClient.keepAlive(), reply);
}

Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi, Your code doesn't help…

Hi,

Your code doesn't help. It doesn't tell anything about what you are trying to do.
What kind of data are you sending and what the meter is replying?

BR,
Mikko

Akash

2 years 5 months ago

in my case First step …

in my case

First step : i am getting Meter Number

second step : i am enabling secure handshake and trying to get meter data
some times i am getting data some time i am not getting data some time

Data sent failed Error Alert coming

16:07:30.238Tx: 7E A0 1F 03 21 93 76 27 81 80 13 05 01 80 06 02 02 00 07 04 00 00 00 01 08 04 00 00 00 01 B4 F9 7E

16:07:30.321Rx: 7E A0 1F 21 03 73 78 66 81 80 13 05 02 01 00 06 01 80 07 04 00 00 00 01 08 04 00 00 00 01 FD FE 7E

16:07:30.327Tx: 7E A0 2B 03 21 10 FB AF E6 E6 00 60 1D A1 09 06 07 60 85 74 05 08 01 01 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 42 1E 5D FF FF 19 35 7E
16:07:30.449Rx: 7E A0 37 21 03 30 6C 7C E6 E7 00 61 29 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00 A3 05 A1 03 02 01 00 BE 10 04 0E 08 00 06 5F 1F 04 00 00 00 10 02 26 00 07 FE 3F 7E

16:07:30.456Tx: 7E A0 19 03 21 32 6F D8 E6 E6 00 C0 01 C1 00 01 00 00 2B 01 03 FF 02 00 B0 AA 7E
16:07:30.529Rx: 7E A0 15 21 03 52 5D 8A E6 E7 00 C4 01 C1 00 06 00 0F 56 0A C7 7A 7E
16:07:30.535Tx: 7E A0 11 03 21 54 87 3B E6 E6 00 62 03 80 01 00 BD 9B 7E
16:07:30.593Rx: 7E A0 11 21 03 74 85 BC E6 E7 00 63 03 80 01 00 2C 0F 7E
16:07:30.598Tx: 7E A0 07 03 21 53 03 C7 7E

16:07:30.663Rx: 7E A0 1E 21 03 73 C3 7A 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 04 00 00 00 01 53 3B 7E
16:07:31.181Tx: 7E A0 1F 03 61 93 10 61 81 80 13 05 01 80 06 02 02 00 07 04 00 00 00 01 08 04 00 00 00 01 B4 F9 7E

Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi, Are you using Java or…

Hi,

Are you using Java or Xamarin (C#)?

BR,
Mikko

Akash

2 years 5 months ago

i am Using Java

i am Using Java

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 08/26/2026 - 09:04
    Gurux.DLMS.Python 1.0.203
  • Mon, 08/17/2026 - 11:28
    Gurux.DLMS.Python 1.0.202
  • Mon, 08/17/2026 - 09:47
    gurux.dlms.cpp 9.0.2608.1701
  • Mon, 08/17/2026 - 09:25
    gurux.dlms.c 9.0.2608.1701
  • Mon, 07/27/2026 - 12:37
    gurux.dlms.cpp 9.0.2607.2701

New forum topics

  • Security vulnerability report — request for a private contact (GuruxDLMS.c / ANSI C)
  • Topic: Insufficient Memory Error When Reading Class 7 Profile Generic Objects
  • SN ReadResponse returns all-null values when response spans multiple HDLC frames
  • Gurux.Serial.Android 3.0.6 – CH340 (HL-340) USB-Serial Adapter Not Working,
  • Trying to talk to a L&G E360 meter (Using Python Gurux)
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin