private static void SaveUnitCharge(GXXmlWriter writer, string name, GXUnitCharge charge, int index) { writer.WriteStartElement(name, index); writer.WriteElementString("Scale", charge.ChargePerUnitScaling.CommodityScale, index); writer.WriteElementString("PriceScale", charge.ChargePerUnitScaling.PriceScale, index); if (charge.Commodity.Target != null) { writer.WriteElementString("Type", (int)charge.Commodity.Target.ObjectType, index); writer.WriteElementString("Ln", charge.Commodity.Target.LogicalName, index); } else { writer.WriteElementString("Type", 0, index); writer.WriteElementString("Ln", "0.0.0.0.0.0", index); } writer.WriteElementString("Index", charge.Commodity.Index, index); writer.WriteStartElement("ChargeTables", 0); if (charge.ChargeTables != null) { foreach (GXChargeTable it in charge.ChargeTables) { writer.WriteStartElement("Item", 0); writer.WriteElementString("Index", it.Index, index); writer.WriteElementString("ChargePerUnit", it.ChargePerUnit, index); writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteEndElement(); }
private void SetUnitCharge(GXUnitCharge charge, object value) { List <object> tmp = (List <object>)value; List <object> tmp2 = (List <object>)tmp[0]; charge.ChargePerUnitScaling.CommodityScale = (sbyte)tmp2[0]; charge.ChargePerUnitScaling.PriceScale = (sbyte)tmp2[1]; tmp2 = (List <object>)tmp[1]; ObjectType ot = (ObjectType)Convert.ToInt32(tmp2[0]); string ln = GXCommon.ToLogicalName(tmp2[1]); charge.Commodity.Target = Parent.FindByLN(ot, ln); charge.Commodity.Index = (sbyte)tmp2[2]; List <GXChargeTable> list = new List <GXChargeTable>(); tmp2 = (List <object>)tmp[2]; foreach (List <object> it in tmp2) { GXChargeTable item = new GXChargeTable(); item.Index = ASCIIEncoding.ASCII.GetString((byte[])it[0]); item.ChargePerUnit = (Int16)it[1]; list.Add(item); } charge.ChargeTables = list.ToArray(); }
private static void LoadUnitChargeActive(GXXmlReader reader, string name, GXUnitCharge charge) { if (reader.IsStartElement(name, true)) { charge.ChargePerUnitScaling.CommodityScale = (sbyte)reader.ReadElementContentAsInt("Scale"); charge.ChargePerUnitScaling.PriceScale = (sbyte)reader.ReadElementContentAsInt("PriceScale"); ObjectType ot = (ObjectType)reader.ReadElementContentAsInt("Type"); string ln = reader.ReadElementContentAsString("Ln"); charge.Commodity.Target = reader.Objects.FindByLN(ot, ln); charge.Commodity.Index = reader.ReadElementContentAsInt("Index"); List <GXChargeTable> list = new List <GXChargeTable>(); if (reader.IsStartElement("ChargeTables", true)) { while (reader.IsStartElement("Item", true)) { GXChargeTable it = new GXChargeTable(); it.Index = reader.ReadElementContentAsString("Index"); it.ChargePerUnit = (short)reader.ReadElementContentAsInt("ChargePerUnit"); list.Add(it); } reader.ReadEndElement("ChargeTables"); } reader.ReadEndElement(name); charge.ChargeTables = list.ToArray(); } }
private static byte[] GetUnitCharge(GXDLMSSettings settings, GXUnitCharge charge) { GXByteBuffer bb = new GXByteBuffer(); bb.SetUInt8(DataType.Structure); bb.SetUInt8(3); bb.SetUInt8(DataType.Structure); bb.SetUInt8(2); GXCommon.SetData(settings, bb, DataType.Int8, charge.ChargePerUnitScaling.CommodityScale); GXCommon.SetData(settings, bb, DataType.Int8, charge.ChargePerUnitScaling.PriceScale); bb.SetUInt8(DataType.Structure); bb.SetUInt8(3); if (charge.Commodity.Target == null) { GXCommon.SetData(settings, bb, DataType.UInt16, 0); bb.SetUInt8(DataType.OctetString); bb.SetUInt8(6); bb.SetUInt8(0); bb.SetUInt8(0); bb.SetUInt8(0); bb.SetUInt8(0); bb.SetUInt8(0); bb.SetUInt8(0); GXCommon.SetData(settings, bb, DataType.Int8, 0); } else { GXCommon.SetData(settings, bb, DataType.UInt16, charge.Commodity.Target.ObjectType); GXCommon.SetData(settings, bb, DataType.OctetString, GXCommon.LogicalNameToBytes(charge.Commodity.Target.LogicalName)); GXCommon.SetData(settings, bb, DataType.Int8, charge.Commodity.Index); } bb.SetUInt8(DataType.Array); if (charge.ChargeTables == null) { bb.SetUInt8(0); } else { GXCommon.SetObjectCount(charge.ChargeTables.Length, bb); foreach (GXChargeTable it in charge.ChargeTables) { bb.SetUInt8(DataType.Structure); bb.SetUInt8(2); GXCommon.SetData(settings, bb, DataType.OctetString, it.Index); GXCommon.SetData(settings, bb, DataType.Int16, it.ChargePerUnit); } } return(bb.Array()); }
private void SetUnitCharge(GXUnitCharge charge, object value) { if (value != null) { List <object> tmp, tmp2, it; if (value is List <object> ) { tmp = (List <object>)value; } else { tmp = new List <object>((object[])value); } if (tmp[0] is List <object> ) { tmp2 = (List <object>)tmp[0]; } else { tmp2 = new List <object>((object[])tmp[0]); } charge.ChargePerUnitScaling.CommodityScale = (sbyte)tmp2[0]; charge.ChargePerUnitScaling.PriceScale = (sbyte)tmp2[1]; if (tmp[1] is List <object> ) { tmp2 = (List <object>)tmp[1]; } else { tmp2 = new List <object>((object[])tmp[1]); } ObjectType ot = (ObjectType)Convert.ToInt32(tmp2[0]); string ln = GXCommon.ToLogicalName(tmp2[1]); if (ot != ObjectType.None) { if (Parent != null) { charge.Commodity.Target = Parent.FindByLN(ot, ln); } else { charge.Commodity.Target = GXDLMSClient.CreateObject(ot); charge.Commodity.Target.LogicalName = ln; } } else { charge.Commodity.Target = null; } charge.Commodity.Index = (sbyte)tmp2[2]; List <GXChargeTable> list = new List <GXChargeTable>(); foreach (object tmp3 in (IEnumerable <object>)tmp[2]) { if (tmp3 is List <object> ) { it = (List <object>)tmp3; } else { it = new List <object>((object[])tmp3); } GXChargeTable item = new GXChargeTable(); item.Index = ASCIIEncoding.ASCII.GetString((byte[])it[0]); item.ChargePerUnit = (Int16)it[1]; list.Add(item); } charge.ChargeTables = list.ToArray(); } else { charge.ChargePerUnitScaling.CommodityScale = 0; charge.ChargePerUnitScaling.PriceScale = 0; charge.Commodity.Target = null; charge.Commodity.Index = 0; charge.ChargeTables = new GXChargeTable[0]; } }
/// <summary> /// Constructor. /// </summary> /// <param name="ln">Logical Name of the object.</param> /// <param name="sn">Short Name of the object.</param> public GXDLMSCharge(string ln, ushort sn) : base(ObjectType.Charge, ln, sn) { UnitChargeActive = new GXUnitCharge(); UnitChargePassive = new GXUnitCharge(); }
private static void SaveUnitChargeActive(GXXmlWriter writer, string name, GXUnitCharge charge, int index) { }
private static void LoadUnitChargeActive(GXXmlReader reader, string name, GXUnitCharge charge) { }