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

4 posts / 0 new
Last post
nafeezabrar
Sending sepecific reading request (e.g. clock rate, voltage) To Meter or DCU

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?

kurumi
kurumi's picture
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();
}
}
}

________________________________________
Mikko Kurunsaari
Gurux Ltd
Hermiankatu 6-8 H 33720 TAMPERE, FINLAND
Phone: +358 3 265 1244
Home page: http://www.gurux.org

Swappage
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>

kurumi
kurumi's picture
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=7EA019030376CCCCE6E600...

BR,

Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
Hermiankatu 6-8 H 33720 TAMPERE, FINLAND
Phone: +358 3 265 1244
Home page: http://www.gurux.org