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. Xml To Message

Xml To Message

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 Paul , 8 February, 2021
Forums
Gurux.Net

Hi,

I'm having some challenges in reading profile data from an unfamiliar meter type, where I'm able to read the configured profiles, but not values within a profile (Access Violated error), however values able to read and display GXDLMSDirector.

Trying to figure this out, I stumbled onto the GXDLMSTranslator class listened to the byte arrays between the meter and GXDLMSDirector and was able to decode the byte arrays (messages) to xml for the messages and pdus respectively.

My idea is to edit the xml respectively, and then to encode the xml back to a byte array and send the meter... therefore reading profile data by specified time frames in this manner. This now, is also where I'm stuck:

available functions:
DatatoXml <-> XmltoData
PduoXml <-> XmltoPdu
MessagetoXml <-> ?? (can't see available function?)

code so far:

var translator = new GXDLMSTranslator(Gurux.DLMS.Enums.TranslatorOutputType.SimpleXml);
var xml = translator.MessageToXml(input);

byte[] pdu = translator.GetPdu(input);
string pduxml = translator.PduToXml(pdu);
//-> change pdu text here
byte[] pduEncoded = translator.XmlToPdu(pduxml);
string hexPdu = translator.XmlToHexPdu(pduxml);

//need to set message pdu equal to new pdu
//need to encode xml back to binary

Any suggestions, or already-available approaches please?

Profile picture for user Kurumi

Kurumi

5 years 4 months ago

Hi,

Hi,

Check this:
https://github.com/Gurux/Gurux.DLMS.Net/tree/master/Gurux.DLMS.XmlClient

I believe it will do what you want to do.

BR,
Mikko

Paul

5 years 4 months ago

In reply to Hi, by Kurumi

Thank you Mikko, this will

Thank you Mikko, this will certainly be very useful! (and thank you for the fast response)

Following the recommendations I tried an example to read a register value via a list of xml commands (1) SNRM, (2) AARQ, (3) value read (4) Disconnect. Using the msg translater, the xml decoding for snrm requests looks like:

cmd: 7E A0 07 03 21 93 0F 01 7E

xml:
<HDLC len="9" >
<TargetAddress Value="1" />
<SourceAddress Value="10" />
<!-- SNRM frame. -->
<FrameType Value="93" />
<Snrm>
</Snrm>
</HDLC>

Unfortunately, an exception is already thrown on this SNRM command with the msg "Invalid Command: targetaddress" (targetaddress tag value = 65285, and thus not found in switch statement under GXDLMSTranslator -> GetCommand)

Not sure if my xml commands are contructed correctly then? I tested the translator on both the Gurux website, as well as on GXDLMSDirecotor (screenshot attached)

Image
Profile picture for user Kurumi

Kurumi

5 years 4 months ago

Hi,

Hi,

Don't add SNRM or AARQ commands. They have added automatically when the connection is established. You can change AARQ parameters like a password with command line parameters.

BR,
Mikko

Paul

5 years 4 months ago

Ok, noted, thanks. Removed

Ok, noted, thanks. Removed them from list of commands so that only a value read command is present for execution. The exception however still persists, with output in console being:

------------------------------------------------------------
3ValRead
------------------------------------------------------------
Invalid Command: TargetAddress

The xml command representation is (as created by GXDLMSDirector):

<HDLC len="16" >
<TargetAddress Value="1" />
<SourceAddress Value="16" />
<!--I frame.-->
<FrameType Value="32" />
<PDU>
<ReadRequest Qty="1" >
<VariableName Value="1008" />
</ReadRequest>
</PDU>
</HDLC>

The input parameters I specify to the execution is: -r SN -S COM3:9600:8None1 -x xmlFiles
(with the xmlCommands stored in the specified directory)

Profile picture for user Kurumi

Kurumi

5 years 4 months ago

Hi,

Hi,

XML client messages are a little bit different than in GXDLMSDirector.
Just convert your short name reference value to hex. Try with this.
1008 = 0x3F0

<?xml version="1.0" encoding="utf-8"?>
<Messages>
<ReadRequest Qty="01" >
<VariableName Value="3F0" />
</ReadRequest>
</Messages>

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