void IGXDLMSBase.SetValue(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) { 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) { DataType type = CaptureObjects[pos].Key.GetUIDataType(CaptureObjects[pos].Value.AttributeIndex); 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; } } } 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; } if (lastDate != DateTime.MinValue) { lastDate = lastDate.AddSeconds(CapturePeriod); row[pos] = new GXDateTime(lastDate); } } if (CaptureObjects[pos].Key is GXDLMSRegister && CaptureObjects[pos].Value.AttributeIndex == 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 (Parent != null) { obj = Parent.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); } GXDLMSClient.UpdateOBISCodes(objects); } 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."); } }