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));
}
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
The type in the gxc file is…
The type in the gxc file is int16, but the agent still has a datetime error
The type in the gxc file is…
The type in the gxc file is int16, but the agent still has a datetime error
When I modified this code on…
When I modified this code on the Agent client, the write operation worked
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
Thanks for your reply,…
Thanks for your reply, looking forward to the next version