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. How To Perform a Simple Reading From a Register In C# .NET

How to perform a simple reading from a register in C# .NET

By jlloyd , 24 September, 2024
Forums
Gurux.DLMS

I have attempted to write a simple Server and Client based on the GitHub examples, and comments on this forum, I can make a connection but I cant seem to read register data. The register has no value or unit when I attempt to read.

Server Code:

using System.Diagnostics;
using Gurux.DLMS.Enums;
using Gurux.DLMS.Objects;
using GuruxDlmsTest.Server;

var server = new GXDLMSServerLN_47();

var register = new GXDLMSRegister("1.1.1.8.0.255")
{
Scaler = 1.0,
Unit = Unit.ActiveEnergy,
Value = 2637.35,
};

server.Items.Add(register);

server.Initialize(4059, TraceLevel.Verbose);

var thread = new Thread(() => DoWork(server));
thread.Start();

ConsoleKey k;
while ((k = Console.ReadKey().Key) != ConsoleKey.Escape)
{
if (k == ConsoleKey.Delete)
{
Console.Clear();
}
Console.WriteLine("Press Esc to close application or delete clear the console.");
}

server.Close();

return;

static void DoWork(object param)
{
AutoResetEvent wait = new AutoResetEvent(false);
GXDLMSBase server = (GXDLMSBase)param;
while (true)
{
int wt = server.Run(wait);
Console.WriteLine($"Waiting {TimeSpan.FromSeconds(wt)} before next execution.");
wait.WaitOne(wt * 1000);
}
// ReSharper disable once FunctionNeverReturns
}

Server Output:

Client Read value from 0.0.1.0.0.255 attribute: 2.
Client Read value from 1.1.21.25.0.255 attribute: 2.
Waiting 00:00:10 before next execution.
Client Connected.
RX: 00 01 00 10 00 01 00 1F 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 62 1E 5D FF FF
Connected.
TX: 00 01 00 01 00 10 00 2B 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 00 10 04 00 00 07
Client Read value from 0.0.1.0.0.255 attribute: 2.
Client Read value from 1.1.21.25.0.255 attribute: 2.
Waiting 00:01:00 before next execution.
RX: 00 01 00 10 00 01 00 05 62 03 80 01 00
Disconnected
TX: 00 01 00 01 00 10 00 17 63 11 80 01 00 BE 0F 04 0E 08 00 06 5F 1F 04 00 00 00 10 04 00 00 07
Client Disconnected.

Client Code:

using System.Diagnostics;
using Gurux.DLMS.Enums;
using Gurux.DLMS.Objects;
using Gurux.DLMS.Secure;
using Gurux.Net;
using GuruxDlmsTest.Client;
using Task = System.Threading.Tasks.Task;

var secureClient = new GXDLMSSecureClient(
true,
16,
1,
Authentication.None,
"",
InterfaceType.WRAPPER);

var media = new GXNet(NetworkType.Tcp, "127.0.0.1", 4059);

var reader = new GXDLMSReader(
secureClient,
media,
TraceLevel.Verbose,
"0.0.43.1.8.255");

reader.OnNotification += data =>
{
Console.WriteLine(data);
};

media.Open();

Thread.Sleep(1000);

reader.InitializeConnection();

var register = new GXDLMSRegister("1.1.1.8.0.255");
secureClient.Read(register, 3);

Thread.Sleep(1000);

secureClient.Read(register, 2);

Thread.Sleep(1000);

Console.WriteLine($"Register reading: {register.Unit} {register.Value}");

await Task.Delay(10_000);

reader.Close();

Client Output:

Standard: DLMS
Send AARQ request
TX: 11:28:53 00 01 00 10 00 01 00 1F 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 62 1E 5D FF FF
RX: 11:28:53 00 01 00 01 00 10 00 2B 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 00 10 04 00 00 07
Parsing AARE reply61 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 00 10 04 00 00 07
Conformance: Get
Parsing AARE reply succeeded.
Register reading: None
Disconnecting from the meter.
Release from the meter.
TX: 11:29:05 00 01 00 10 00 01 00 05 62 03 80 01 00
RX: 11:29:05 00 01 00 01 00 10 00 17 63 11 80 01 00 BE 0F 04 0E 08 00 06 5F 1F 04 00 00 00 10 04 00 00 07

Profile picture for user Kurumi

Kurumi

1 year 8 months ago

Hi, You have genrated the…

Hi,

You have genrated the read request in the client side, but you didn't sent it to the meter.

Change this line:
secureClient.Read(register, 3);
To this:

reader.Read(register, 3);

The reader will send the request to the meter. Secure client generates the bytes, but it doesn't send them to the meter.

BR,
Mikko

jlloyd

1 year 8 months ago

Hi Kurumi, thanks for the…

Hi Kurumi, thanks for the response,

I now get the error:

Unhandled exception. Gurux.DLMS.GXDLMSException: Access Error : Device reports Read-Write denied.

Is this because no authentication, or because of some sort of access rights for the register?

I will likely want to implement authentication later, are there docs for this? If the register is the issue, how do I allow read access on it?

Is there a discord/slack/other chat for this library? Or some more thorough client and server .NET examples?

Profile picture for user Kurumi

Kurumi

1 year 8 months ago

Hi, It might be that you…

Hi,

It might be that you haven't given the access rights for the register. Check ValidateAuthentication.

I believe those links will help you:
https://www.gurux.fi/Gurux.DLMS.Server
https://www.gurux.fi/Gurux.DLMS.Client

We can help only our customers with chat and email.

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
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin