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. Can't Reproduce DLMSDirector's In Java Code.

Can't reproduce DLMSDirector's in Java Code.

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By bleg , 14 February, 2019
Forums
General discussion

Hello Experts.
DLMS Director manages to succesfully read values from a secured meter.
But when i try to do same stuff in Java, i see the error "Invalid HDLC Frame: 50 Expected: 30".
That's it.

The device is using Pre-established accosiation, so the steps are:
1. Connect to public client with no ciphering.
2. Read invocation counter
3. Send disconnect
4. Connect using Management client (01)
5. Don't send AARQ since it's pre-established.
6. Read the stuff.

DLMS Director does this good, but Java library cant.

Everything is in pictures.
Need help.

Image

bleg

7 years 3 months ago

The java code

The java code

Image

bleg

7 years 3 months ago

+

DLMS Director trace

Image

bleg

7 years 3 months ago

+

Java trace

Image
Profile picture for user Kurumi

Kurumi

7 years 3 months ago

Can't reproduce DLMSDirector's in Java Code.

Hi,

Please, post trace as text. It's easier to read than pic. We need to improve client app. It don't read invocation counter automatically.

Uncomment generate AARQ parseAARE section for now. Then change client address from 0x10 to 1.
You need also update invocation counter manually.

BR,
Mikko

bleg

7 years 3 months ago

+

Here's the trace from Client JAVA app:

TX: 21:24:39.724 7E A0 07 03 21 93 0F 01 7E
RX: 21:24:39.758 7E A0 07 21 03 73 01 40 7E
TX: 21:24:39.758 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 00 1E 1D FF FF C5 E4 7E
RX: 21:24:39.943 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 02 14 00 E5 00 07 30 C6 7E
TX: 21:24:39.952 7E A0 19 03 21 32 6F D8 E6 E6 00 C0 01 C1 00 01 00 00 2A 00 00 FF 02 00 12 80 7E
RX: 21:24:40.032 7E A0 22 21 03 52 8E 91 E6 E7 00 C4 01 C1 00 09 10 46 49 4F 52 30 33 34 31 31 38 31 39 30 32 32 30 C8 98 7E
TX: 21:24:40.047 7E A0 19 03 21 54 5F DE E6 E6 00 C0 01 C1 00 01 00 01 2B 01 01 FF 02 00 13 0C 7E
RX: 21:24:40.125 7E A0 15 21 03 74 69 CE E6 E7 00 C4 01 C1 00 06 80 00 02 2D 44 FC 7E
Index: 2 Value: 46 49 4F 52 30 33 34 31 31 38 31 39 30 32 32 30
Index: 2 Value: 2147484205
TX: 21:24:40.125 7E A0 07 03 21 53 03 C7 7E
RX: 21:24:40.172 7E A0 07 21 03 73 01 40 7E
TX: 21:24:40.187 7E A0 07 03 03 93 8C 11 7E
RX: 21:24:40.247 7E A0 07 03 03 73 82 F6 7E
TX: 21:24:40.255 7E A0 2C 03 03 32 49 EA E6 E6 00 C8 1E 30 00 00 01 A0 B8 C8 C5 68 A0 A9 98 5E 04 93 3A 58 0A 73 F0 B2 12 CF 72 16 14 24 E9 EE 28 45 6C 7E

And here's the source code:
// ----------- 1. Connect using public client (16)
// create client instance
GXDLMSSecureClient client = new GXDLMSSecureClient(true, 16, 1, Authentication.NONE, null, Itype);
client.getProposedConformance().addAll(GXDLMSClient.getInitialConformance(true));

// create reader instance
reader = new GXDLMSReader(client, settings.media, settings.trace);

// open media
settings.media.open();

// SNRM handshake
reader.initializeConnection();

// see conformance
System.out.println(client.getNegotiatedConformance());

// ----------- 2. Read Invocation Counter (0.0.43.1.1.255)
obj = GXDLMSClient.createObject(ObjectType.DATA);
obj.setLogicalName("0.1.43.1.1.255");
Object val_ic = reader.read(obj,2);

// show values
reader.showValue(2, val_ic);

// ----------- 3. Disconnect (without closing media)
reader.close(false, false); (first argument: close media? / second argument: send release?)

// ----------- 4. Compute server system title, Client system title, and key
byte[] cst = GXCommon.hexToBytes("5341435341435341"); // client system title
byte[] key = GXCommon.hexToBytes("4BFE5EDD86F0B34EF4BCBE5BD4C2D91F"); // encryption key
byte[] sst = GXCommon.hexToBytes("2F19200219184103"); // server system title

// ----------- 5. Connect as secured client.
GXDLMSSecureClient scl = client;
scl.setClientAddress(1);
scl.getCiphering().setSecurity(Security.AUTHENTICATION_ENCRYPTION);
scl.getCiphering().setSecuritySuite(SecuritySuite.AES_GCM_128);
scl.getCiphering().setAuthenticationKey(key);
scl.getCiphering().setBlockCipherKey(key);
scl.getCiphering().setSystemTitle(sst);
scl.getCiphering().setRecipientSystemTitle(cst);
scl.setServerSystemTitle(sst);
scl.getCiphering().setInvocationCounter(Long.parseLong(val_ic.toString()));

// --- test the secured client
reader.initializeConnection(true); // first argument: pre-establushed? (E.c. dont send AARQ)
// see conformance
System.out.println(client.getNegotiatedConformance());

obj = GXDLMSClient.createObject(ObjectType.DATA);
obj.setLogicalName("0.1.43.1.1.255");
val_ic = reader.read(obj,1); // <<<<---- here it fails
reader.showValue(1, val_ic);

} catch (Exception ex) {
System.out.println(ex.getMessage());
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(1);
}
}
System.out.println("Ended. Press any key to continue.");
}
}

The output is:
Authentication: None
ClientAddress: 0x10
ServerAddress: 0x1
[MULTIPLE_REFERENCES, GET, SELECTIVE_ACCESS]
Index: 2 Value: 2147484205
DisconnectRequest
[MULTIPLE_REFERENCES, GET, SELECTIVE_ACCESS]
Invalid HDLC Frame: 50 Expected: 30
Data send failed. Try to resend 1/3
Data send failed. Try to resend 2/3

PS: This forked from Gurux client app example.
The changes in fucntions of GXDLMSReader class:

void initializeConnection(boolean pre_established) throws Exception, InterruptedException {
<...skipped...>
if (!pre_established) {
reply.clear();
readDataBlock(dlms.aarqRequest(), reply);
// Parse reply.
dlms.parseAareResponse(reply.getData());
reply.clear();

// Get challenge Is HLS authentication is used.
if (dlms.getAuthentication().getValue() > Authentication.LOW
.getValue()) {
for (byte[] it : dlms.getApplicationAssociationRequest()) {
readDLMSPacket(it, reply);
}
dlms.parseApplicationAssociationResponse(reply.getData());
}

void close(boolean close_media, boolean release) throws Exception {
if (Media != null && Media.isOpen()) {
System.out.println("DisconnectRequest");
GXReplyData reply = new GXReplyData();
if (release) {
try {
readDataBlock(dlms.releaseRequest(), reply);
} catch (Exception e) {
// All meters don't support release.
}
}
reply.clear();
readDLMSPacket(dlms.disconnectRequest(), reply);
if (close_media) {
Media.close();
}
}
}

bleg

7 years 3 months ago

If I try to send AARQ when in

If I try to send AARQ when in secured mode (client 01). The meter responds 'Service not allowed'. As companion documentations says, it is pre-established.

Profile picture for user Kurumi

Kurumi

7 years 3 months ago

If I try to send AARQ when in

Hi,
You don't send AARQ in pre-established. You need to comment that out. We'll improve example to handle pre-established connections.

BR,

Mikko

bleg

7 years 3 months ago

I know! And i dont send it!

I know! And i dont send it! But still reading fails. Any suggestion on possible reason? May be i am missing something?

bleg

7 years 3 months ago

There’s also a confusion in

There’s also a confusion in methods for setting system titles.
There are two methods:
client itself has setServerSystemTitle()
then ciphering also has setSystemTitle() and setRecipientSystemTitle()
i use all of them (see code above). Which ones are correct to use?

bleg

7 years 3 months ago

seems to be a bug

it was an invocation counter that caused error (now its working). i traced my com port and meter is responding okay. it seems that reader cannot properly recieve the bytes. the inhandled exception occurs, that says: “Invalid HDLC Frame: 50 Expected: 30". is there a bug in java library?

Profile picture for user Kurumi

Kurumi

7 years 3 months ago

If I try to send AARQ when in

Hi,

Good if you find the problem. I'll check your Invalid HDLC Frame problem.
Return true in checkFrame method . I believe that fixes your problem.

Problem is that different meters are expecting different value for the first HDLC frame and they are returning different values. C# is skipping check when pre-established connections are used. I'm just designing the solution how we can handle all the meters and how to define what value to use as the first HDLC frame value.

BR,
Mikko

bleg

7 years 3 months ago

Thank you. It worked!

Thank you. It worked!

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin