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. Agent Wirte Data(TImezone) Exception

Agent wirte Data(TImezone) Exception

By xsmy, 10 May, 2024
Forums
Gurux.DLMS.AMI

When I try to write Clock Timezone data, the following error occurs on the Agent client

-----------------------------------------------------
fail: Gurux.DLMS.AMI.Agent.Worker.GXAgentWorker[0]
2024/5/10 15:59:22 Failed to execute task Write #3 started String '<Int16 Value="-480" />
' was not recognized as a valid DateTime. String '<Int16 Value="-480" />
' was not recognized as a valid DateTime.

-----------------------------------------------------------
I analyzed the Agent source code and found that when writing data, the Attr data type to be written was not set to the Object, but a default value was obtained. I guess it's this that causes the exception

The following is this code
------------------------------------------------------------
GXDLMSObject obj;
if (task.Object != null && task.Object.Template != null)
{
obj = GXDLMSClient.CreateObject((ObjectType)task.Object.Template.ObjectType);
obj.Version = task.Object.Template.Version.GetValueOrDefault(0);
obj.LogicalName = task.Object.Template.LogicalName;
obj.ShortName = task.Object.Template.ShortName.GetValueOrDefault();
}
else if (task.Attribute != null && task.Attribute.Object != null &&
task.Attribute.Object.Template != null)
{
if (task.Attribute.Object.Template.ObjectType == null)
{
throw new Exception("Invalid object type.");
}
obj = GXDLMSClient.CreateObject((ObjectType)task.Attribute.Object.Template.ObjectType);
// obj.Version = task.Object.Template.Version.GetValueOrDefault(0);
obj.LogicalName = task.Attribute.Object.Template.LogicalName;
obj.ShortName = task.Attribute.Object.Template.ShortName.GetValueOrDefault();
}
else if (task.Device?.Objects != null)
{
foreach (var it in task.Device.Objects)
{
task.Object = it;
await ExecuteTasks(dev, reader, cl, task);
}
return;
}
else
{
throw new ArgumentException("Invalid object.");
}
if (task.TaskType == TaskType.Write)
{
DataType dt = obj.GetDataType(2);
DataType uiDt = obj.GetUIDataType(2);
_logger?.LogInformation(DateTime.Now + " DataType: "+dt+ " , UIDataType: "+ uiDt);
//If date-time value is updated.
if (uiDt == DataType.DateTime ||
uiDt == DataType.Date ||
uiDt == DataType.Time)
{
if (dt == DataType.OctetString)
{
//If value is null currect date time is used.
if (string.IsNullOrEmpty(task.Data))
{
if (dt == DataType.OctetString || dt == DataType.DateTime || dt == DataType.Date || dt == DataType.Time)
{
cl.UpdateValue(obj, task.Index.GetValueOrDefault(0), DateTime.Now);
}
else
{
cl.UpdateValue(obj, task.Index.GetValueOrDefault(0), GXDateTime.ToUnixTime(DateTime.UtcNow));
}
}
else
{
if (uiDt == DataType.DateTime)
{
cl.UpdateValue(obj, task.Index.GetValueOrDefault(0), new GXDateTime(task.Data, CultureInfo.InvariantCulture));
}
else if (uiDt == DataType.Date)
{
cl.UpdateValue(obj, task.Index.GetValueOrDefault(0), new GXDate(task.Data, CultureInfo.InvariantCulture));
}
else if (uiDt == DataType.Time)
{
cl.UpdateValue(obj, task.Index.GetValueOrDefault(0), new GXTime(task.Data, CultureInfo.InvariantCulture));
}
}
}
}
else
{
cl.UpdateValue(obj, task.Index.GetValueOrDefault(0), GXDLMSTranslator.XmlToValue(task.Data));
}
reader.Write(obj, task.Index.GetValueOrDefault(0));
}

Profile picture for user Kurumi

Kurumi

1 year 6 months ago

Hi, I believe that the time…

Hi,

I believe that the time zone data type is changed to DateTime for some reason. It should be Int16. Check that and change it to the Int16. It can also be changed in GXDLMSDirector. Check that it's correct.

BR,
Mikko

xsmy

1 year 6 months ago

The type in the gxc file is…

The type in the gxc file is int16, but the agent still has a datetime error

Image

xsmy

1 year 6 months ago

The type in the gxc file is…

The type in the gxc file is int16, but the agent still has a datetime error

Image

xsmy

1 year 6 months ago

When I modified this code on…

When I modified this code on the Agent client, the write operation worked

Image
Profile picture for user Kurumi

Kurumi

1 year 5 months ago

Hi, You are right. Clock…

Hi,
You are right. Clock write was broked when another issue was fixed.
The new version will be released tomorrow.

BR,
Mikko

xsmy

1 year 5 months ago

Thanks for your reply,…

Thanks for your reply, looking forward to the next version

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 10/29/2025 - 08:51
    gurux.dlms.c 9.0.2510.2901
  • Thu, 10/16/2025 - 09:59
    gurux.dlms.java 4.0.83
  • Wed, 10/08/2025 - 10:21
    gurux.dlms.c 9.0.2510.0801
  • Fri, 09/26/2025 - 10:02
    gurux.dlms.cpp 9.0.2509.2601
  • Fri, 09/26/2025 - 09:45
    gurux.dlms.c 9.0.2509.2601

New forum topics

  • Guidance on using the source codes
  • How to get/convert user readable format data from readRowsByRange
  • Insufficient memory to continue the execution of the program.
  • The client instance code failed to connect to the electricity meter for authentication
  • Unable to Release Request when closing connection with meter.
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin