void IGXDLMSBase.Load(GXXmlReader reader) { Buffer = GXCommon.HexToBytes(reader.ReadElementContentAsString("Buffer")); CaptureObjects.Clear(); if (reader.IsStartElement("CaptureObjects", true)) { while (reader.IsStartElement("Item", true)) { ObjectType ot = (ObjectType)reader.ReadElementContentAsInt("ObjectType"); string ln = reader.ReadElementContentAsString("LN"); int ai = reader.ReadElementContentAsInt("Attribute"); int di = reader.ReadElementContentAsInt("Data"); GXDLMSCaptureObject co = new GXDLMSCaptureObject(ai, di); GXDLMSObject obj = reader.Objects.FindByLN(ot, ln); if (obj == null) { obj = GXDLMSClient.CreateObject(ot); obj.LogicalName = ln; } CaptureObjects.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, co)); } reader.ReadEndElement("CaptureObjects"); } TemplateId = (byte)reader.ReadElementContentAsInt("TemplateId"); TemplateDescription = GXCommon.HexToBytes(reader.ReadElementContentAsString("TemplateDescription")); CaptureMethod = (CaptureMethod)reader.ReadElementContentAsInt("CaptureMethod"); }
void IGXDLMSBase.Load(GXXmlReader reader) { Buffer.Clear(); if (reader.IsStartElement("Buffer", true)) { while (reader.IsStartElement("Row", true)) { List <object> row = new List <object>(); while (reader.IsStartElement("Cell", false)) { row.Add(reader.ReadElementContentAsObject("Cell", null)); } Buffer.Add(row.ToArray()); } reader.ReadEndElement("Buffer"); } CaptureObjects.Clear(); if (reader.IsStartElement("CaptureObjects", true)) { while (reader.IsStartElement("Item", true)) { ObjectType ot = (ObjectType)reader.ReadElementContentAsInt("ObjectType"); string ln = reader.ReadElementContentAsString("LN"); int ai = reader.ReadElementContentAsInt("Attribute"); int di = reader.ReadElementContentAsInt("Data"); GXDLMSCaptureObject co = new GXDLMSCaptureObject(ai, di); GXDLMSObject obj = reader.Objects.FindByLN(ot, ln); if (obj == null) { obj = GXDLMSClient.CreateObject(ot); obj.LogicalName = ln; } CaptureObjects.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, co)); } reader.ReadEndElement("CaptureObjects"); } CapturePeriod = reader.ReadElementContentAsInt("CapturePeriod"); SortMethod = (SortMethod)reader.ReadElementContentAsInt("SortMethod"); if (reader.IsStartElement("SortObject", true)) { CapturePeriod = reader.ReadElementContentAsInt("CapturePeriod"); ObjectType ot = (ObjectType)reader.ReadElementContentAsInt("ObjectType"); string ln = reader.ReadElementContentAsString("LN"); SortObject = reader.Objects.FindByLN(ot, ln); reader.ReadEndElement("SortObject"); } EntriesInUse = reader.ReadElementContentAsInt("EntriesInUse"); ProfileEntries = reader.ReadElementContentAsInt("ProfileEntries"); }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, int index, object value) { if (index == 1) { if (value is string) { LogicalName = value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString(); } } else if (index == 2) { if (CaptureObjects == null || CaptureObjects.Count == 0) { throw new Exception("Read capture objects first."); } if (value != null && (value as object[]).Length != 0) { int index2 = 0; DateTime lastDate = DateTime.MinValue; foreach (object[] row in (value as object[])) { if ((row as object[]).Length != CaptureObjects.Count) { throw new Exception("Number of columns do not match."); } for (int pos = 0; pos != row.Length; ++pos) { index2 = CaptureObjects[pos].Value.AttributeIndex; DataType type; //Actaris SL 7000 and ACE 6000 returns 0. if (index2 != 0) { type = CaptureObjects[pos].Key.GetUIDataType(index2); } else { type = DataType.None; } if (row[pos] is byte[]) { if (type != DataType.None && row[pos] is byte[]) { row[pos] = GXDLMSClient.ChangeType(row[pos] as byte[], type); if (row[pos] is GXDateTime) { GXDateTime dt = (GXDateTime)row[pos]; lastDate = dt.Value.LocalDateTime; } } } else if (type == DataType.DateTime && row[pos] == null && CapturePeriod != 0) { if (lastDate == DateTime.MinValue && Buffer.Count != 0) { lastDate = ((GXDateTime)Buffer[Buffer.Count - 1].GetValue(pos)).Value.LocalDateTime; } if (lastDate != DateTime.MinValue) { lastDate = lastDate.AddSeconds(CapturePeriod); row[pos] = new GXDateTime(lastDate); } } if (CaptureObjects[pos].Key is GXDLMSRegister && index2 == 2) { double scaler = (CaptureObjects[pos].Key as GXDLMSRegister).Scaler; if (scaler != 1) { try { row[pos] = Convert.ToDouble(row[pos]) * scaler; } catch { //Skip error } } } } Buffer.Add(row); } EntriesInUse = Buffer.Count; } } else if (index == 3) { Buffer.Clear(); EntriesInUse = 0; CaptureObjects.Clear(); GXDLMSObjectCollection objects = new GXDLMSObjectCollection(); foreach (object it in value as object[]) { object[] tmp = it as object[]; if (tmp.Length != 4) { throw new GXDLMSException("Invalid structure format."); } ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]); string ln = GXDLMSObject.ToLogicalName((byte[])tmp[1]); int attributeIndex = Convert.ToInt16(tmp[2]); int dataIndex = Convert.ToInt16(tmp[3]); GXDLMSObject obj = null; if (settings != null && settings.Objects != null) { obj = settings.Objects.FindByLN(type, ln); } if (obj == null) { obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0); } CaptureObjects.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(attributeIndex, dataIndex))); objects.Add(obj); } } else if (index == 4) { CapturePeriod = Convert.ToInt32(value); } else if (index == 5) { SortMethod = (SortMethod)Convert.ToInt32(value); } else if (index == 6) { if (value != null) { object[] tmp = value as object[]; if (tmp.Length != 4) { throw new GXDLMSException("Invalid structure format."); } ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]); string ln = GXDLMSObject.ToLogicalName((byte[])tmp[1]); SortAttributeIndex = Convert.ToInt16(tmp[2]); SortDataIndex = Convert.ToInt16(tmp[3]); SortObject = null; foreach (var it in CaptureObjects) { if (it.Key.ObjectType == type && it.Key.LogicalName == ln) { SortObject = it.Key; break; } } } else { SortObject = null; } } else if (index == 7) { EntriesInUse = Convert.ToInt32(value); } else if (index == 8) { ProfileEntries = Convert.ToInt32(value); } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { if (e.Value is string) { LogicalName = e.Value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString(); } } else if (e.Index == 2) { SetBuffer(settings, e); } else if (e.Index == 3) { Reset(); CaptureObjects.Clear(); GXDLMSObjectCollection objects = new GXDLMSObjectCollection(); if (e.Value != null) { foreach (object it in e.Value as object[]) { object[] tmp = it as object[]; if (tmp.Length != 4) { throw new GXDLMSException("Invalid structure format."); } ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]); string ln = GXDLMSObject.ToLogicalName((byte[])tmp[1]); int attributeIndex = Convert.ToInt16(tmp[2]); int dataIndex = Convert.ToInt16(tmp[3]); GXDLMSObject obj = null; if (settings != null && settings.Objects != null) { obj = settings.Objects.FindByLN(type, ln); } if (obj == null) { obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0); } CaptureObjects.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(attributeIndex, dataIndex))); objects.Add(obj); } } } else if (e.Index == 4) { //Any write access to one of the attributes will automatically call a reset //and this call will propagate to all other profiles capturing this profile. if (settings.IsServer) { Reset(); } CapturePeriod = Convert.ToInt32(e.Value); } else if (e.Index == 5) { //Any write access to one of the attributes will automatically call a reset //and this call will propagate to all other profiles capturing this profile. if (settings.IsServer) { Reset(); } SortMethod = (SortMethod)Convert.ToInt32(e.Value); } else if (e.Index == 6) { //Any write access to one of the attributes will automatically call a reset //and this call will propagate to all other profiles capturing this profile. if (settings.IsServer) { Reset(); } if (e.Value != null) { object[] tmp = e.Value as object[]; if (tmp.Length != 4) { throw new GXDLMSException("Invalid structure format."); } ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]); string ln = GXDLMSObject.ToLogicalName((byte[])tmp[1]); SortAttributeIndex = Convert.ToInt16(tmp[2]); SortDataIndex = Convert.ToInt16(tmp[3]); SortObject = null; foreach (var it in CaptureObjects) { if (it.Key.ObjectType == type && it.Key.LogicalName == ln) { SortObject = it.Key; break; } } if (SortObject == null) { SortObject = GXDLMSClient.CreateObject(type); SortObject.LogicalName = ln; } } else { SortObject = null; } } else if (e.Index == 7) { EntriesInUse = Convert.ToInt32(e.Value); } else if (e.Index == 8) { //Any write access to one of the attributes will automatically call a reset //and this call will propagate to all other profiles capturing this profile. if (settings.IsServer) { Reset(); } ProfileEntries = Convert.ToInt32(e.Value); } else { e.Error = ErrorCode.ReadWriteDenied; } }