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. Forums
  3. Sending Sepecific Reading Request (e.g. Clock Rate, Voltage) To Meter or DCU

Sending sepecific reading request (e.g. clock rate, voltage) To Meter or DCU

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 nafeezabrar , 9 January, 2018
Forums
Gurux.Net

Hi

I am new in GuruX and DLMS. I have connected with DCU using Gurux.DLMS.Meter.Listener.Net (by changing the port number, client address, server address, authentication and password).

It could send and receive the SNRM and AARQ.

But I could not figure out how to read data from DCU or meter? Where can I find code snippet of converting XML to PDU send corresponding DLMS packet over TCP?

Profile picture for user Kurumi

Kurumi

8 years 5 months ago

Sending sepecific reading request (e.g. clock rate, voltage) To

Hi,

We don't have publish xml example for listener at the moment. You can modify this for your needs.

/// <summary>
/// Is command in XML file.
/// </summary>
/// <param name="actions"></param>
/// <param name="command"></param>
/// <returns></returns>
static bool ContainsCommand(List<GXDLMSXmlPdu> actions, Command command)
{
foreach (GXDLMSXmlPdu it in actions)
{
if (it.Command == command)
{
return true;
}
}
return false;
}

/// <summary>
/// Handle meter reply.
/// </summary>
/// <param name="item">Command to sent.</param>
/// <param name="reply">Received reply.</param>
static void HandleReply(GXDLMSXmlPdu item, GXReplyData reply)
{
if (reply.Value is byte[])
{
Console.WriteLine(GXCommon.ToHex((byte[])reply.Value, true));
}
else
{
Console.WriteLine(Convert.ToString(reply));
}
}

/// <summary>
/// Read data from the meter.
/// </summary>
private static void ReadXmlMeter(GXNet media)
{
TraceLevel trace = TraceLevel.Error;
GXDLMSXmlClient client = new GXDLMSXmlClient(Enums.TranslatorOutputType.SimpleXml);
GXDLMSReader reader = null;
List<string> files = new List<string>();
try
{
reader = new GXDLMSReader(client, media, TraceLevel.Verbose);
string path;
if (client.UseLogicalNameReferencing)
{
path = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "Messages\\LN");
}
else
{
path = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "Messages\\SN");
}
FileAttributes attr = File.GetAttributes(path);
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
{
files.AddRange(Directory.GetFiles(path, "*.xml"));
}
else
{
files.Add(path);
}
//Execute messages.
foreach (string file in files)
{
string name = Path.GetFileNameWithoutExtension(file);
if (trace > TraceLevel.Warning)
{
Console.WriteLine("------------------------------------------------------------");
Console.WriteLine(name);
}
List<GXDLMSXmlPdu> actions = client.Load(file);
if (actions.Count == 0)
{
continue;
}
try
{
media.Open();
reader = new Reader.GXDLMSReader(client, media, trace);
GXReplyData reply = new GXReplyData();
//Send SNRM if not in xml.
if (client.InterfaceType == InterfaceType.HDLC)
{
if (!ContainsCommand(actions, Command.Snrm))
{
reader.SNRMRequest();
}
}

//Send AARQ if not in xml.
if (!ContainsCommand(actions, Command.Aarq))
{
if (!ContainsCommand(actions, Command.Snrm))
{
reader.AarqRequest();
}
}

foreach (GXDLMSXmlPdu it in actions)
{
if (it.Command == Command.Snrm && client.InterfaceType == InterfaceType.WRAPPER)
{
continue;
}
if (it.Command == Command.DisconnectRequest && client.InterfaceType == InterfaceType.WRAPPER)
{
break;
}
//Send
reply.Clear();
if (trace > TraceLevel.Warning)
{
Console.WriteLine("------------------------------------------------------------");
Console.WriteLine(it.ToString());
}
if (it.IsRequest())
{
reader.ReadDataBlock(client.PduToMessages(it), reply);
HandleReply(it, reply);
}
}
}
catch (Exception ex)
{
Console.WriteLine("------------------------------------------------------------");
Console.WriteLine(ex.Message);
}
finally
{
//Send AARQ if not in xml.
if (!ContainsCommand(actions, Command.DisconnectRequest))
{
reader.Disconnect();
}
else
{
media.Close();
}
}

}
}
finally
{
if (reader != null)
{
reader.Close();
}
}
}

Swappage

8 years 4 months ago

Hi,

Hi,
i'm jumping into this conversation as it's extremely interesting

i'm trying to dig into the XML client too, as i have a bunch of XML files i need to send to my meter.

The problem is that most likely my XMLs are not interpreted correctly as i always receive exceptions from the application.

Do you have an examle XML file to share containing some basic commands?

mine are something like this:

<ROOT>

<HdlcOpen ClientId="16"/>
<DlmsOpen ClientId="16"/>

<GetRequest>
<GetRequestNormal>
<InvokeIdAndPriority Value="C1"/>
<AttributeDescriptor Descr="LDN">
<ClassId Value="1"/>
<InstanceId OBIS="0-0:42.0.0.255"/>
<AttributeId Value="2"/>
</AttributeDescriptor>
</GetRequestNormal>
</GetRequest>

<GetRequest>
<GetRequestNormal>
<InvokeIdAndPriority Value="C1"/>
<AttributeDescriptor Descr="Offline Management Frame Counter">
<ClassId Value="1"/>
<InstanceId OBIS="0-1:43.1.1.255"/>
<AttributeId Value="2"/>
</AttributeDescriptor>
</GetRequestNormal>
</GetRequest>

</ROOT>

Profile picture for user Kurumi

Kurumi

8 years 4 months ago

XML client

Hi,
You should check Gurux.DLMS.XmlClient from
https://github.com/gurux/gurux.dlms.net

Only PDU is described on xml files. There are few examples.
You can genrate xml by your self using GXDLMSTranslator.
Read your meter with GXDLMSDirector and get sent bytes. Then Paste send bytes to GuruxDLMSTranslator and press "To Messages" button. It will genrerate XML for you.

Check this example:
http://www.gurux.fi/GuruxDLMSTranslator?translate=7EA019030376CCCCE6E60…

BR,

Mikko

  • 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