Skip to main content
Home
for DLMS smart meters

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Where I Put Meter Ipv6 and Port and Destination Address Pls Help or Share File Name

where i put meter ipv6 and port and destination address pls help or share file name

Profile picture for user sushil@2793
By sushil@2793, 18 September, 2024
Forums
Gurux.Net

using System;
using Gurux.Common;
using Gurux.DLMS;
using Gurux.DLMS.Enums;
using Gurux.Net;
using System.Text;

class Program
{
static void Main(string[] args)
{
GXNet connection = null;

try
{
// Create and configure the GXDLMSClient
var client = new GXDLMSClient
{
InterfaceType = InterfaceType.General,
UseLogicalNameReferencing = true,
ClientAddress = 0x21,
ServerAddress = 0x3,
Authentication = Authentication.None // No authentication
};

// Create and configure the connection
connection = new GXNet
{
HostName = "1111:1111::2",
Port = 3333
};

// Open the connection
connection.Open();

if (!connection.IsOpen)
{
throw new Exception("Connection could not be opened.");
}

GXReplyData reply = new GXReplyData();

// Send SNRM request and handle response
byte[] snrmRequest = client.SNRMRequest();
if (snrmRequest != null)
{
ReadDLMSPacket(connection, snrmRequest, reply);
client.ParseUAResponse(reply.Data);
Console.WriteLine("SNRM/UA negotiation succeeded.");
}
else
{
throw new Exception("SNRM request is null.");
}

// Send AARQ request and handle AARE response
foreach (byte[] aarqRequest in client.AARQRequest())
{
if (aarqRequest != null)
{
reply.Clear();
ReadDLMSPacket(connection, aarqRequest, reply);
client.ParseAAREResponse(reply.Data);
}
else
{
throw new Exception("AARQ request is null.");
}
}

Console.WriteLine("AARQ/AARE negotiation succeeded.");
Console.WriteLine("Connection established successfully!");

// Read and display data from the meter
ReadDataFromMeter(client, connection);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
finally
{
// Ensure the connection is closed
if (connection != null && connection.IsOpen)
{
connection.Close();
}
}
}

// This method reads DLMS packets from the connection
private static void ReadDLMSPacket(GXNet connection, byte[] data, GXReplyData reply)
{
try
{
connection.Send(data, data.Length);
connection.Receive(new ReceiveParameters<byte[]> { AllData = true, Eop = (byte)0x7E, Count = 5, WaitTime = 1000 });
reply.Data = connection.Receive(new ReceiveParameters<byte[]> { AllData = true, Eop = (byte)0x7E, Count = 5, WaitTime = 1000 });
}
catch (Exception ex)
{
throw new Exception("Error reading DLMS packet: " + ex.Message);
}
}

// Reads data from the meter and displays it on the console
private static void ReadDataFromMeter(GXDLMSClient client, GXNet connection)
{
try
{
// Send the get objects request
byte[] getObjectsRequest = client.GetObjectsRequest();
GXReplyData reply = new GXReplyData();
ReadDLMSPacket(connection, getObjectsRequest, reply);

// Parse the response
var objects = client.ParseObjects(reply.Data, true);
foreach (var obj in objects)
{
// Read the value of each object
// Assuming 'Read' method requires object reference and possibly other parameters
var value = client.Read(obj.ObjectType, obj.LogicalName, null); // Adjust arguments as needed
Console.WriteLine($"Object: {obj.LogicalName}, Value: {value}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error reading data from meter: {ex.Message}");
}
}
}

Profile picture for user sushil@2793

sushil@2793

8 months ago

Severity Code Description…

Severity Code Description Project File Line Suppression State
Error CS0029 Cannot implicitly convert type 'byte[][]' to 'byte[]' dlms C:\Users\Administrator.WIN-1HTSJ8KGNJH\Desktop\dlms\Program.cs 112 Active
Error CS1503 Argument 2: cannot convert from 'string' to 'Gurux.DLMS.Enums.ObjectType' dlms C:\Users\Administrator.WIN-1HTSJ8KGNJH\Desktop\dlms\Program.cs 122 Active
Error CS1503 Argument 3: cannot convert from '<null>' to 'int' dlms C:\Users\Administrator.WIN-1HTSJ8KGNJH\Desktop\dlms\Program.cs 122 Active

Profile picture for user Kurumi

Kurumi

8 months ago

Hi, Does this error occur…

Hi,

Does this error occur when you are reading objects or when reading the association view?

BR,
Mikko

  • Log in or register to post comments
  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 05/20/2025 - 08:40
    gurux.dlms.c 9.0.2505.2001
  • Mon, 05/19/2025 - 10:19
    gurux.net.java 1.0.30
  • Mon, 05/19/2025 - 10:00
    gurux.dlms.c 9.0.2505.1901
  • Thu, 05/15/2025 - 16:26
    gurux.dlms.c 9.0.2505.1501
  • Wed, 05/14/2025 - 08:30
    gurux.dlms.c 9.0.2505.1401

New forum topics

  • Reading all "Data" object type parameter together
  • com_read getting failed for billing profile and instantaneous profile
  • Simulator connection closed
  • Regarding the dlms android project
  • Issue with "ServiceError Initiate Error exception. Service UNSUPPORTED"
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin