How to read DLMS without using GXNet nor GXSerial

8 posts / 0 new
Last post
khun_panya
How to read DLMS without using GXNet nor GXSerial

This page https://github.com/Gurux/Gurux.DLMS.Net
says that Gurux.Net nor Gurux.Serial is not necessary.
But the examples have extensively used GXSerial and GXNet.
How can we implement ReadDLMSPacket method by using just simple TcpClient ?
Please show some example. Thanks.

khun_panya

OK. Here is my progress. I write a sub

private static byte[] SendAndReceive(TcpClient net, byte[] command)
{
var ns = net.GetStream();
ns.Write(command, 0, command.Length);
System.Threading.Thread.Sleep(100);
var buff = new byte[1024];
using (var ms = new System.IO.MemoryStream())
{
int len;
while (ns.DataAvailable)
{
len = ns.Read(buff, 0, buff.Length);
ms.Write(buff, 0, len);
}
return ms.ToArray();
}
}

And here is my main program

var net = new TcpClient();
net.Connect("xxx.xxx.xxx.xxx", 6001); // Landis+Gyr meter

var client = new GXDLMSClient();
client.UseLogicalNameReferencing = false;
client.InterfaceType = InterfaceType.HDLC;
client.ServerAddress = 1;
client.ClientAddress = 16;

var send = client.SNRMRequest();
var recv = SendAndReceive(net, send);
client.ParseUAResponse(new GXByteBuffer(recv));

But now the problem is ParseUAResponse throws GXDLMSException("Invalid Exception.").
Why is that? Lines below are send and recv binary.

7E A0 07 03 21 93 0F 01 7E
7E A0 1E 21 03 73 C3 7A 81 80 12 05 01 80 06 01 3E 07 04 00 00 00 01 08 04 00 00 00 01 07 22 7E

Kurumi
Kurumi's picture

Hi,

Your code looks good and your settings are correct. What version from gurux.dlms.java you are using?
I just tested this and it worked like should be. I was using the same settings that you are.
Check what is reply data in new GXByteBuffer(recv).

BR,
Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi

khun_panya

Hi,
I'm using latest Gurux.DLMS for C# v8.5.1904.401. Downloaded from NuGet.
It looks like the exception was thrown because the 5th byte of GXByteBuffer data was 03
which is not listed in switch-case within GXDLMS.ParseSnrmUaResponse(…).

Kurumi
Kurumi's picture

Hi,

Now I believe what it the reason. Before you call ParseUAResponse you need to call GetData.
GXReplyData reply = new GXReplyData();
client.GetData(recv, reply);
client.ParseUAResponse(reply.Data);

BR,
Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi

khun_panya

That works perfectly! Thank you!

balaramjenagate

while I am running Gurux.Serial.Android Master android app error: cannot find symbol method getPorts() is coming

Kurumi
Kurumi's picture

Hi,

When you have new question, please, create a new topic. Have you imported serial port in to your android app? What version you are using from Android Studio?

BR,
Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi