object GetValue(object target, int index, List <object> UpdatedObjects) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(target); foreach (PropertyDescriptor it in properties) { GXDLMSAttributeSettings i = it.Attributes[typeof(GXDLMSAttributeSettings)] as GXDLMSAttributeSettings; if (i != null && i.Index == index) { return(it.GetValue(target)); } else if (it.PropertyType.IsClass) { if (it.PropertyType == typeof(string)) { continue; } //If component is not already searched. if (!UpdatedObjects.Contains(target)) { UpdatedObjects.Add(target); GetValue(it.GetValue(target), index, UpdatedObjects); } } } return(null); }
private static GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> CreateColumn(GXDLMSObjectCollection objects, GXObisCodeCollection obisCodes, ObjectType ot, string ln, int index, DataType dt) { GXDLMSObject obj = objects.FindByLN(ot, ln); if (obj == null) { GXObisCode code = obisCodes.FindByLN(ot, ln, null); obj = GXDLMSClient.CreateObject(ot); obj.LogicalName = ln; if (code != null) { GXDLMSAttributeSettings s = code.Attributes.Find(index); if (s != null) { obj.SetDataType(index, s.Type); obj.SetUIDataType(index, s.UIType); obj.SetValues(index, s.Values); } } else { obj.SetUIDataType(index, dt); } } return(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(index, 0))); }
/// <summary> /// Update enumeration values. /// </summary> /// <param name="index"></param> /// <param name="values"></param> public void SetValues(int index, GXObisValueItemCollection values) { GXDLMSAttributeSettings att = GetAttribute(index, Attributes); att.Values.Clear(); att.Values.AddRange(values); }
/// <summary> /// Returns is Method attribute read only. /// </summary>- /// <param name="index">Method Attribute index.</param> /// <returns>Is attribute read only.</returns> public MethodAccessMode GetMethodAccess(int index) { GXDLMSAttributeSettings att = MethodAttributes.Find(index); if (att != null) { return(att.MethodAccess); } return(MethodAccessMode.Access); }
/// <summary> /// Set Method attribute access. /// </summary> /// <param name="index"></param> /// <param name="access"></param> public void SetMethodAccess(int index, MethodAccessMode access) { GXDLMSAttributeSettings att = MethodAttributes.Find(index); if (att == null) { att = new GXDLMSAttributeSettings(index); MethodAttributes.Add(att); } att.MethodAccess = access; }
/// <inheritdoc cref="GXDLMSObject.UpdateDefaultValueItems"/> public override void UpdateDefaultValueItems() { GXDLMSAttributeSettings att = this.Attributes.Find(5); if (att == null) { att = new GXDLMSAttribute(5); Attributes.Add(att); } att.Values.Add(new GXObisValueItem(SortMethod.FiFo, "FIFO")); att.Values.Add(new GXObisValueItem(SortMethod.LiFo, "LIFO")); att.Values.Add(new GXObisValueItem(SortMethod.Largest, "Largest")); att.Values.Add(new GXObisValueItem(SortMethod.Smallest, "Smallest")); att.Values.Add(new GXObisValueItem(SortMethod.NearestToZero, "Nearest To Zero")); att.Values.Add(new GXObisValueItem(SortMethod.FarestFromZero, "Farest from Zero")); }
private void GetAccessRights(GXDLMSObject item, GXByteBuffer data) { data.SetUInt8((byte)DataType.Structure); data.SetUInt8((byte)2); data.SetUInt8((byte)DataType.Array); GXAttributeCollection attributes = item.Attributes; int cnt = (item as IGXDLMSBase).GetAttributeCount(); data.SetUInt8((byte)cnt); for (int pos = 0; pos != cnt; ++pos) { GXDLMSAttributeSettings att = attributes.Find(pos + 1); data.SetUInt8((byte)DataType.Structure); //attribute_access_item data.SetUInt8((byte)3); GXCommon.SetData(data, DataType.Int8, pos + 1); //If attribute is not set return read only. if (att == null) { GXCommon.SetData(data, DataType.Enum, AccessMode.Read); } else { GXCommon.SetData(data, DataType.Enum, att.Access); } GXCommon.SetData(data, DataType.None, null); } data.SetUInt8((byte)DataType.Array); attributes = item.MethodAttributes; cnt = (item as IGXDLMSBase).GetMethodCount(); data.SetUInt8((byte)cnt); for (int pos = 0; pos != cnt; ++pos) { GXDLMSAttributeSettings att = attributes.Find(pos + 1); data.SetUInt8((byte)DataType.Structure); //attribute_access_item data.SetUInt8((byte)2); GXCommon.SetData(data, DataType.Int8, pos + 1); //If method attribute is not set return no access. if (att == null) { GXCommon.SetData(data, DataType.Enum, MethodAccessMode.NoAccess); } else { GXCommon.SetData(data, DataType.Enum, att.MethodAccess); } } }
protected GXDLMSAttributeSettings GetAttribute(int index, GXAttributeCollection attributes) { GXDLMSAttributeSettings att = this.Attributes.Find(index); if (att == null) { att = new GXDLMSAttributeSettings(index); //LN is read only. if (index == 1) { att.Access = AccessMode.Read; } if (attributes != null) { attributes.Add(att); } } return(att); }
private void UpdateAttributes() { bindingSource1.Clear(); List <GXDLMSAttributeSettings> list = new List <GXDLMSAttributeSettings>(); string[] names = (Target as IGXDLMSBase).GetNames(); for (int pos = 0; pos != (Target as IGXDLMSBase).GetAttributeCount(); ++pos) { GXDLMSAttributeSettings a = new GXDLMSAttributeSettings() { Index = pos + 1, Name = names[pos] }; Target.Attributes.Add(a); //Logical name is always read-only. if (pos == 0) { if (version < 3) { a.Access = AccessMode.Read; } else { a.Access3 = AccessMode3.Read; } } else { if (version < 3) { AccessMode mode = Target.GetAccess(1 + pos); a.Access = mode; } else { AccessMode3 mode = Target.GetAccess3(1 + pos); a.Access3 = mode; } } list.Add(a); } foreach (var it in list) { bindingSource1.Add(it); } Accessrights.DataSource = bindingSource1; //Show method access levels of COSEM object. bindingSource3.Clear(); list.Clear(); //Add all methods. names = (Target as IGXDLMSBase).GetMethodNames(); for (int pos = 0; pos != (Target as IGXDLMSBase).GetMethodCount(); ++pos) { GXDLMSAttributeSettings a = new GXDLMSAttributeSettings() { Index = pos + 1, Name = names[pos] }; Target.MethodAttributes.Add(a); if (version < 3) { MethodAccessMode mode = Target.GetMethodAccess(1 + pos); a.MethodAccess = mode; } else { MethodAccessMode3 mode = Target.GetMethodAccess3(1 + pos); a.MethodAccess3 = mode; } list.Add(a); } foreach (var it in list) { bindingSource3.Add(it); } MethodAccessrights.DataSource = bindingSource3; }
/// <summary> /// Set attribute access. /// </summary> /// <param name="index"></param> /// <param name="access"></param> public void SetAccess(int index, AccessMode access) { GXDLMSAttributeSettings att = GetAttribute(index, Attributes); att.Access = access; }
/// <summary> /// Returns is attribute read only. /// </summary>- /// <param name="index">Attribute index.</param> /// <returns>Is attribute read only.</returns> public AccessMode GetAccess(int index) { GXDLMSAttributeSettings att = GetAttribute(index, null); return(att.Access); }
/// <summary> /// How this value is visualized on the UI. /// </summary> /// <param name="index"></param> /// <returns></returns> public ValueFieldType GetUIValueType(int index) { GXDLMSAttributeSettings att = GetAttribute(index, null); return(att.UIValueType); }
/// <summary> /// How this value is visualized on the UI. /// </summary> public void SetUIValueType(int index, ValueFieldType value) { GXDLMSAttributeSettings att = GetAttribute(index, Attributes); att.UIValueType = value; }
/// <summary> /// Update XML template. /// </summary> /// <param name="index"></param> /// <param name="values"></param> public void SetXml(int index, string xml) { GXDLMSAttributeSettings att = GetAttribute(index, Attributes); att.Xml = xml; }
/// <summary> /// Returns is Method attribute read only. /// </summary>- /// <param name="index">Method Attribute index.</param> /// <returns>Is attribute read only.</returns> public byte GetAccessSelector(int index) { GXDLMSAttributeSettings att = GetAttribute(index, Attributes); return(att.AccessSelector); }
public void SetStatic(int index, bool isStatic) { GXDLMSAttributeSettings att = GetAttribute(index, Attributes); att.Static = isStatic; }
/// <summary> /// Set Method attribute access. /// </summary> /// <param name="index"></param> /// <param name="access"></param> public void SetAccessSelector(int index, byte value) { GXDLMSAttributeSettings att = GetAttribute(index, Attributes); att.AccessSelector = value; }
/// <summary> /// This method is used to solve Column's data type in Profile Generic table. /// </summary> /// <param name="component"></param> /// <param name="attributeIndex"></param> /// <returns></returns> internal static DataType GetAttributeType(GXDLMSObject component, int attributeIndex) { if (attributeIndex != 0) { if (attributeIndex > 0x10) { attributeIndex = 2; } GXDLMSAttributeSettings att2 = component.Attributes.Find(attributeIndex); if (att2 != null && att2.Type != DataType.None) { return(att2.Type); } PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(component); foreach (PropertyDescriptor pd in pdc) { GXDLMSAttributeSettings att = (GXDLMSAttributeSettings)pd.Attributes[typeof(GXDLMSAttributeSettings)]; if (att != null) { if (att.Index == attributeIndex) { if (att.UIType != DataType.None) { return(att.UIType); } //If expected type is not given return property type. if (pd.PropertyType == typeof(Int32)) { return(DataType.Int32); } if (pd.PropertyType == typeof(UInt32)) { return(DataType.UInt32); } if (pd.PropertyType == typeof(String)) { return(DataType.String); } if (pd.PropertyType == typeof(byte)) { return(DataType.UInt8); } if (pd.PropertyType == typeof(sbyte)) { return(DataType.Int8); } if (pd.PropertyType == typeof(Int16)) { return(DataType.Int16); } if (pd.PropertyType == typeof(UInt16)) { return(DataType.UInt16); } if (pd.PropertyType == typeof(Int64)) { return(DataType.Int64); } if (pd.PropertyType == typeof(UInt64)) { return(DataType.UInt64); } if (pd.PropertyType == typeof(float)) { return(DataType.Float32); } if (pd.PropertyType == typeof(double)) { return(DataType.Float64); } if (pd.PropertyType == typeof(DateTime)) { return(DataType.DateTime); } if (pd.PropertyType == typeof(Boolean) || pd.PropertyType == typeof(bool)) { return(DataType.Boolean); } if (pd.PropertyType == typeof(object)) { return(DataType.None); } } } } } return(DataType.None); }
public void UpdateValueItems(GXDLMSObject target, int index, object value) { if (InvokeRequired) { this.BeginInvoke(new UpdateValueItemsEventHandler(UpdateValueItems), target, index, value); } else { GXDLMSAttributeSettings tmp = GXDLMSClient.GetAttributeInfo(target, index); if (tmp != null) { Items = tmp.Values; } else { Items = null; } if (this.Type == GXValueFieldType.TextBox) { this.Type = Items == null || Items.Count == 0 ? GXValueFieldType.TextBox : GXValueFieldType.CompoBox; } else if (this.Type == GXValueFieldType.CompoBox) { comboBox1.Items.Clear(); if (Items != null && Items.Count != 0) { foreach (GXObisValueItem it in Items) { comboBox1.Items.Add(it.UIValue); } } else if (value is Enum) { foreach (var it in Enum.GetValues(value.GetType())) { comboBox1.Items.Add(it); } } } else if (this.Type == GXValueFieldType.ListBox) { listBox1.Items.Clear(); if (value is Enum) { foreach (var it in Enum.GetValues(value.GetType())) { listBox1.Items.Add(it); } } } else if (this.Type == GXValueFieldType.CheckedListBox) { checkedlistBox1.Items.Clear(); if (value is Enum) { foreach (var it in Enum.GetValues(value.GetType())) { checkedlistBox1.Items.Add(it); } } } ReadOnly = (target.GetAccess(index) & AccessMode.Write) == 0; } }
/// <summary> /// Returns UI data type of selected index. /// </summary> /// <param name="index">Attribute index of the object.</param> /// <returns>UI data type of the object.</returns> public virtual DataType GetUIDataType(int index) { GXDLMSAttributeSettings att = GetAttribute(index, null); return(att.UIType); }
void UpdateData(DataTable dt) { if (target.CaptureObjects.Count == 0) { return; } if (structures) { List <object[]> data = new List <object[]>(); foreach (object[] r in target.Buffer) { List <object> row = new List <object>(); int index = 0; foreach (var it in target.CaptureObjects) { //If COSEM object is selected. //Only few meters are supporting this. if (it.Value.AttributeIndex == 0 && r[index] is List <object> ) { //Values must be update to the list because there might be Register Scaler //and it expects that scaler is read before value is updated. GXDLMSObject obj = GXDLMSClient.CreateObject(it.Key.ObjectType); byte i2 = 1; Dictionary <byte, object> list = new Dictionary <byte, object>(); foreach (object v in (r[index] as List <object>)) { list.Add(i2, v); ++i2; } //Update values first. foreach (byte i in (obj as IGXDLMSBase).GetAttributeIndexToRead(true)) { ValueEventArgs ve = new ValueEventArgs(obj, i, 0, null); ve.Value = list[i]; (obj as IGXDLMSBase).SetValue(null, ve); } //Show values. for (byte i = 0; i != (obj as IGXDLMSBase).GetAttributeCount(); ++i) { row.Add(GetValue(obj.GetValues()[i])); } } else { row.Add(GetValue(r[index])); } ++index; } data.Add(row.ToArray()); } for (int pos = dt.Rows.Count; pos < data.Count; ++pos) { object[] row = data[pos]; dt.LoadDataRow(row, true); } } else { for (int pos = dt.Rows.Count; pos < target.Buffer.Count; ++pos) { object[] row = target.Buffer[pos]; if (row != null) { for (int col = 0; col != row.Length; ++col) { if (row[col] is GXDateTime) { if (GXDlmsUi.UseMeterTimeZone) { row[col] = (row[col] as GXDateTime).ToFormatMeterString(); } else { row[col] = (row[col] as GXDateTime).ToFormatString(); } } else if (row[col] is byte[]) { row[col] = GXDLMSTranslator.ToHex((byte[])row[col], true); } else if (row[col] is Object[]) { row[col] = GXDLMSTranslator.ValueToXml(row[col]); } else if (row[col] is GXStructure || row[col] is GXArray) { if (target.CaptureObjects[col].Key is GXDLMSRegister && target.CaptureObjects[col].Value.AttributeIndex == 2) { GXDLMSRegister obj = new GXDLMSRegister(); ValueEventArgs ve = new ValueEventArgs(obj, target.CaptureObjects[col].Value.AttributeIndex, 0, null); ve.Value = row[col]; (obj as IGXDLMSBase).SetValue(null, ve); row[col] = "{" + obj.Scaler + ", " + obj.Unit + "}"; } else { StringBuilder sb = new StringBuilder(); GetArrayAsString(sb, row[col]); row[col] = sb.ToString(); } } else { GXDLMSAttributeSettings att = target.CaptureObjects[col].Key.Attributes.Find(target.CaptureObjects[col].Value.AttributeIndex); if (att != null && att.Values != null) { if (att.Type == DataType.BitString && row[col] is string) { string str = (string)row[col]; if (str.Length != 0 && (str[0] == '0' || str[0] == '1')) { StringBuilder sb = new StringBuilder(); int pos2 = 0; foreach (char it in str) { if (it == '1') { if (sb.Length != 0) { sb.Append(','); } sb.Append(att.Values[pos2].UIValue); } ++pos2; if (pos2 == att.Values.Count) { break; } } row[col] = sb.ToString(); } } else { foreach (GXObisValueItem it in att.Values) { if (IsNumber(row[col]) && it.Value == Convert.ToInt32(row[col])) { row[col] = it.UIValue; break; } } } } } } dt.LoadDataRow(row, true); } } } }
public void SetUIDataType(int index, DataType type) { GXDLMSAttributeSettings att = GetAttribute(index, Attributes); att.UIType = type; }
void UpdateData(DataTable dt) { Standard standard = Standard.DLMS; if (target.Parent != null && target.Parent.Parent is GXDLMSClient) { standard = ((GXDLMSClient)target.Parent.Parent).Standard; } List <object> rows = GXDLMSCompactData.GetData(target.TemplateDescription, target.Buffer, standard == Standard.Italy); if (structures) { List <object[]> data = new List <object[]>(); foreach (List <object> r in rows) { List <object> row = new List <object>(); int index = 0; foreach (var it in target.CaptureObjects) { //If COSEM object is selected. //Only few meters are supporting this. if (it.Value.AttributeIndex == 0 && r[index] is List <object> ) { //Values must be update to the list because there might be Register Scaler //and it expects that scaler is read before value is updated. GXDLMSObject obj = GXDLMSClient.CreateObject(it.Key.ObjectType); byte i2 = 1; Dictionary <byte, object> list = new Dictionary <byte, object>(); foreach (object v in (r[index] as object[])) { list.Add(i2, v); ++i2; } //Update values first. for (byte i = 0; i != (obj as IGXDLMSBase).GetAttributeCount(); ++i) { ValueEventArgs ve = new ValueEventArgs(obj, i, 0, null); ve.Value = list[i]; (obj as IGXDLMSBase).SetValue(null, ve); } //Show values. for (byte i = 0; i != (obj as IGXDLMSBase).GetAttributeCount(); ++i) { row.Add(GetValue(obj.GetValues()[i])); } } else { row.Add(GetValue(r[index])); } ++index; } data.Add(row.ToArray()); } for (int pos = dt.Rows.Count; pos < data.Count; ++pos) { object[] row = data[pos]; dt.LoadDataRow(row, true); } } else { for (int pos = dt.Rows.Count; pos < rows.Count; ++pos) { List <object> row = (List <object>)rows[pos]; if (row != null) { for (int col = 0; col != row.Count; ++col) { if (row[col] is byte[]) { if (pos < target.CaptureObjects.Count && target.CaptureObjects[col].Key.GetUIDataType(target.CaptureObjects[col].Value.AttributeIndex) == DataType.DateTime) { row[col] = GXDLMSClient.ChangeType(row[col] as byte[], DataType.DateTime); } else { row[col] = GXDLMSTranslator.ToHex((byte[])row[col], true); } } else if (row[col] is Object[]) { row[col] = GXDLMSTranslator.ValueToXml(row[col]); } else if (row[col] is List <Object> ) { row[col] = GXDLMSTranslator.ValueToXml(row[col]); } else if (col < target.CaptureObjects.Count) { GXDLMSAttributeSettings att = target.CaptureObjects[col].Key.Attributes.Find(target.CaptureObjects[col].Value.AttributeIndex); if (att != null && att.Values != null) { if (att.Type == DataType.BitString && row[col] is string) { string str = (string)row[col]; if (str.Length != 0 && (str[0] == '0' || str[0] == '1')) { StringBuilder sb = new StringBuilder(); int pos2 = 0; foreach (char it in str) { if (it == '1') { if (sb.Length != 0) { sb.Append(','); } sb.Append(att.Values[pos2].UIValue); } ++pos2; if (pos2 == att.Values.Count) { break; } } row[col] = sb.ToString(); } } else { foreach (GXObisValueItem it in att.Values) { if (IsNumber(row[col]) && it.Value == Convert.ToInt32(row[col])) { row[col] = it.UIValue; break; } } } } } } if (dt.Columns.Count != 0) { try { dt.LoadDataRow(row.ToArray(), true); } catch (Exception) { //It's OK if this fails. } } } } } }
public bool GetStatic(int index) { GXDLMSAttributeSettings att = GetAttribute(index, null); return(att.Static); }
public void Write(GXDLMSObject obj, int index) { object val; GXReplyData reply = new GXReplyData(); for (int it = 1; it != (obj as IGXDLMSBase).GetAttributeCount() + 1; ++it) { reply.Clear(); if (it == index || (index == 0 && obj.GetDirty(it, out val))) { bool forced = false; GXDLMSAttributeSettings att = obj.Attributes.Find(it); //Read DLMS data type if not known. DataType type = obj.GetDataType(it); if (type == DataType.None) { byte[] data = client.Read(obj, it)[0]; ReadDataBlock(data, "Read object type " + obj.ObjectType, reply); type = reply.DataType; if (type == DataType.None) { throw new Exception("Failed to write value. Data type not set."); } obj.SetDataType(it, type); reply.Clear(); } try { if (att != null && att.ForceToBlocks) { forced = client.ForceToBlocks = true; } foreach (byte[] tmp in client.Write(obj, it)) { ReadDataBlock(tmp, string.Format("Writing object {0}, interface {1}", obj.LogicalName, obj.ObjectType), reply); } obj.ClearDirty(it); //Read data once again to make sure it is updated. reply.Clear(); byte[] data = client.Read(obj, it)[0]; ReadDataBlock(data, string.Format("Reading object {0}, interface {1}", obj.LogicalName, obj.ObjectType), reply); val = reply.Value; if (val is byte[] && (type = obj.GetUIDataType(it)) != DataType.None) { val = GXDLMSClient.ChangeType((byte[])val, type); } client.UpdateValue(obj, it, val); } catch (GXDLMSException ex) { if (ex.ErrorCode == 3) { throw new Exception("Read/Write Failed."); } else { throw ex; } } finally { if (forced) { client.ForceToBlocks = false; } } } } }