void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { LogicalName = GXCommon.ToLogicalName(e.Value); } else if (e.Index == 2) { PushObjectList.Clear(); if (e.Value is object[]) { foreach (object it in e.Value as object[]) { object[] tmp = it as object[]; ObjectType type = (ObjectType)Convert.ToUInt16(tmp[0]); string ln = GXCommon.ToLogicalName(tmp[1]); GXDLMSObject obj = settings.Objects.FindByLN(type, ln); if (obj == null) { obj = GXDLMSClient.CreateObject(type); obj.LogicalName = ln; } GXDLMSCaptureObject co = new GXDLMSCaptureObject(Convert.ToInt32(tmp[2]), Convert.ToInt32(tmp[3])); PushObjectList.Add(new KeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, co)); } } } else if (e.Index == 3) { if (e.Value is object[] tmp) { Service = (ServiceType)Convert.ToInt32(tmp[0]); //LN can be used with HDLC if (((byte[])tmp[1]).Length == 6 && ((byte[])tmp[1])[5] == 0xFF) { Destination = GXCommon.ToLogicalName((byte[])tmp[1]); } else { Destination = (string)GXDLMSClient.ChangeType((byte[])tmp[1], DataType.String, settings.UseUtc2NormalTime); } Message = (MessageType)Convert.ToInt32(tmp[2]); } } else if (e.Index == 4) { CommunicationWindow.Clear(); if (e.Value is object[]) { foreach (object it in e.Value as object[]) { object[] tmp = it as object[]; GXDateTime start = GXDLMSClient.ChangeType((byte[])tmp[0], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime; GXDateTime end = GXDLMSClient.ChangeType((byte[])tmp[1], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime; CommunicationWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end)); } } } else if (e.Index == 5) { RandomisationStartInterval = (ushort)e.Value; } else if (e.Index == 6) { NumberOfRetries = (byte)e.Value; } else if (e.Index == 7) { RepetitionDelay = (ushort)e.Value; } else { e.Error = ErrorCode.ReadWriteDenied; } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { switch (e.Index) { case 1: LogicalName = GXCommon.ToLogicalName(e.Value); break; case 2: { ChangedParameter = new GXDLMSTarget(); List <object> tmp = null; if (e.Value is List <object> ) { tmp = (List <object>)e.Value; } else if (e.Value is object[]) { tmp = new List <object>((object[])e.Value); } if (tmp != null) { if (tmp.Count != 4) { throw new GXDLMSException("Invalid structure format."); } ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]); ChangedParameter.Target = settings.Objects.FindByLN(type, (byte[])tmp[1]); if (ChangedParameter.Target == null) { ChangedParameter.Target = GXDLMSClient.CreateObject(type); ChangedParameter.Target.LogicalName = GXCommon.ToLogicalName((byte[])tmp[1]); } ChangedParameter.AttributeIndex = Convert.ToByte(tmp[2]); ChangedParameter.Value = tmp[3]; } break; } case 3: { if (e.Value == null) { CaptureTime = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } if (e.Value is GXDateTime) { CaptureTime = (GXDateTime)e.Value; } else if (e.Value is String) { DateTime tm; if (!DateTime.TryParse((String)e.Value, out tm)) { CaptureTime = DateTime.ParseExact((String)e.Value, CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern, CultureInfo.CurrentUICulture); } else { CaptureTime = tm; } } else { CaptureTime = Convert.ToDateTime(e.Value); } } break; } case 4: { Parameters.Clear(); if (e.Value != null) { foreach (object it in e.Value as IEnumerable <object> ) { List <object> tmp; if (it is List <object> ) { tmp = (List <object>)it; } else { tmp = new List <object>((object[])it); } if (tmp.Count != 3) { throw new GXDLMSException("Invalid structure format."); } GXDLMSTarget obj = new GXDLMSTarget(); ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]); obj.Target = settings.Objects.FindByLN(type, (byte[])tmp[1]); if (obj.Target == null) { obj.Target = GXDLMSClient.CreateObject(type); obj.Target.LogicalName = GXCommon.ToLogicalName((byte[])tmp[1]); } obj.AttributeIndex = Convert.ToByte(tmp[2]); Parameters.Add(obj); } } break; } default: e.Error = ErrorCode.ReadWriteDenied; break; } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { LogicalName = GXCommon.ToLogicalName(e.Value); } else if (e.Index == 2) { PushObjectList.Clear(); List <object> it; if (e.Value != null) { foreach (object t in (IEnumerable <object>)e.Value) { if (t is List <object> ) { it = (List <object>)t; } else { it = new List <object>((object[])t); } ObjectType type = (ObjectType)Convert.ToUInt16(it[0]); String ln = GXCommon.ToLogicalName(it[1]); GXDLMSObject obj = settings.Objects.FindByLN(type, ln); if (obj == null) { obj = GXDLMSClient.CreateObject(type); obj.LogicalName = ln; } GXDLMSCaptureObject co = new GXDLMSCaptureObject(Convert.ToInt32(it[2]), Convert.ToInt32(it[3])); PushObjectList.Add(new KeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, co)); } } } else if (e.Index == 3) { List <object> tmp = null; if (e.Value is List <object> ) { tmp = (List <object>)e.Value; } else { tmp = new List <object>((object[])e.Value); } if (tmp != null) { Service = (ServiceType)Convert.ToInt32(tmp[0]); //LN can be used with HDLC if (Service == ServiceType.Hdlc && ((byte[])tmp[1]).Length == 6 && ((byte[])tmp[1])[5] == 0xFF) { Destination = GXCommon.ToLogicalName((byte[])tmp[1]); } else { object str = GXDLMSClient.ChangeType((byte[])tmp[1], DataType.String, settings.UseUtc2NormalTime); if (str is string) { Destination = (string)str; } else { Destination = GXCommon.ToHex((byte[])tmp[1], true); } } Message = (MessageType)Convert.ToInt32(tmp[2]); } } else if (e.Index == 4) { CommunicationWindow.Clear(); if (e.Value is List <object> ) { foreach (List <object> it in e.Value as List <object> ) { GXDateTime start = GXDLMSClient.ChangeType((byte[])it[0], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime; GXDateTime end = GXDLMSClient.ChangeType((byte[])it[1], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime; CommunicationWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end)); } } } else if (e.Index == 5) { RandomisationStartInterval = (UInt16)e.Value; } else if (e.Index == 6) { NumberOfRetries = (byte)e.Value; } else if (e.Index == 7) { RepetitionDelay = (UInt16)e.Value; } else { e.Error = ErrorCode.ReadWriteDenied; } }
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) { if (e.Value is string) { PHYReference = e.Value.ToString(); } else { PHYReference = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString(); } } else if (e.Index == 3) { List <GXDLMSPppSetupLcpOption> items = new List <GXDLMSPppSetupLcpOption>(); if (e.Value is Object[]) { foreach (Object[] item in (Object[])e.Value) { GXDLMSPppSetupLcpOption it = new GXDLMSPppSetupLcpOption(); it.Type = (PppSetupLcpOptionType)Convert.ToByte(item[0]); it.Length = Convert.ToByte(item[1]); it.Data = item[2]; items.Add(it); } } LCPOptions = items.ToArray(); } else if (e.Index == 4) { List <GXDLMSPppSetupIPCPOption> items = new List <GXDLMSPppSetupIPCPOption>(); if (e.Value is Object[]) { foreach (Object[] item in (Object[])e.Value) { GXDLMSPppSetupIPCPOption it = new GXDLMSPppSetupIPCPOption(); it.Type = (PppSetupIPCPOptionType)Convert.ToByte(item[0]); it.Length = Convert.ToByte(item[1]); it.Data = item[2]; items.Add(it); } } IPCPOptions = items.ToArray(); } else if (e.Index == 5) { UserName = (byte[])((Object[])e.Value)[0]; Password = (byte[])((Object[])e.Value)[1]; } else { e.Error = ErrorCode.ReadWriteDenied; } }
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).ToString(); } } else if (e.Index == 2) { ShortAddress = Convert.ToUInt16(e.Value); } else if (e.Index == 3) { RcCoord = Convert.ToUInt16(e.Value); } else if (e.Index == 4) { PANId = Convert.ToUInt16(e.Value); } else if (e.Index == 5) { KeyTable.Clear(); if (e.Value != null) { foreach (object v in (object[])e.Value) { object[] tmp = (object[])v; KeyTable.Add(new GXKeyValuePair <byte, byte[]>(Convert.ToByte(tmp[0]), (byte[])tmp[1])); } } } else if (e.Index == 6) { FrameCounter = Convert.ToUInt32(e.Value); } else if (e.Index == 7) { ToneMask = (string)e.Value; } else if (e.Index == 8) { TmrTtl = Convert.ToByte(e.Value); } else if (e.Index == 9) { MaxFrameRetries = Convert.ToByte(e.Value); } else if (e.Index == 10) { NeighbourTableEntryTtl = Convert.ToByte(e.Value); } else if (e.Index == 11) { List <GXDLMSNeighbourTable> list = new List <GXDLMSNeighbourTable>(); if (e.Value != null) { foreach (object v in (object[])e.Value) { object[] tmp = (object[])v; GXDLMSNeighbourTable it = new GXDLMSNeighbourTable(); it.ShortAddress = Convert.ToUInt16(tmp[0]); it.Enabled = Convert.ToBoolean(tmp[1]); it.ToneMap = (string)tmp[2]; it.Modulation = (Modulation)Convert.ToInt32(tmp[3]); it.TxGain = Convert.ToSByte(tmp[4]); it.TxRes = (GainResolution)Convert.ToInt32(tmp[5]); it.TxCoeff = (string)tmp[6]; it.Lqi = Convert.ToByte(tmp[7]); it.PhaseDifferential = Convert.ToSByte(tmp[8]); it.TMRValidTime = Convert.ToByte(tmp[9]); it.NeighbourValidTime = Convert.ToByte(tmp[10]); list.Add(it); } } NeighbourTable = list.ToArray(); } else if (e.Index == 12) { HighPriorityWindowSize = Convert.ToByte(e.Value); } else if (e.Index == 13) { CscmFairnessLimit = Convert.ToByte(e.Value); } else if (e.Index == 14) { BeaconRandomizationWindowLength = Convert.ToByte(e.Value); } else if (e.Index == 15) { A = Convert.ToByte(e.Value); } else if (e.Index == 16) { K = Convert.ToByte(e.Value); } else if (e.Index == 17) { MinCwAttempts = Convert.ToByte(e.Value); } else if (e.Index == 18) { CenelecLegacyMode = Convert.ToByte(e.Value); } else if (e.Index == 19) { FccLegacyMode = Convert.ToByte(e.Value); } else if (e.Index == 20) { MaxBe = Convert.ToByte(e.Value); } else if (e.Index == 21) { MaxCsmaBackoffs = Convert.ToByte(e.Value); } else if (e.Index == 22) { MinBe = Convert.ToByte(e.Value);; } else { e.Error = ErrorCode.ReadWriteDenied; } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { switch (e.Index) { case 1: LogicalName = GXCommon.ToLogicalName(e.Value); break; case 2: TotalAmountPaid = (Int32)e.Value; break; case 3: ChargeType = (ChargeType)Convert.ToByte(e.Value); break; case 4: Priority = (byte)e.Value; break; case 5: SetUnitCharge(UnitChargeActive, e.Value); break; case 6: SetUnitCharge(UnitChargePassive, e.Value); break; case 7: if (e.Value is GXDateTime) { UnitChargeActivationTime = (GXDateTime)e.Value; } else if (e.Value is byte[]) { UnitChargeActivationTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings != null && settings.UseUtc2NormalTime); } else if (e.Value is string) { UnitChargeActivationTime = new GXDateTime((string)e.Value); } else { UnitChargeActivationTime = null; } break; case 8: Period = (UInt32)e.Value; break; case 9: ChargeConfiguration = (ChargeConfiguration)Convert.ToInt32(e.Value); break; case 10: if (e.Value is GXDateTime) { LastCollectionTime = (GXDateTime)e.Value; } else if (e.Value is DateTime) { LastCollectionTime = (DateTime)e.Value; } else if (e.Value is byte[]) { LastCollectionTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings != null && settings.UseUtc2NormalTime); } else if (e.Value is string) { LastCollectionTime = new GXDateTime(e.Value as string); } else { LastCollectionTime = null; } break; case 11: LastCollectionAmount = (Int32)e.Value; break; case 12: TotalAmountRemaining = (Int32)e.Value; break; case 13: Proportion = (UInt16)e.Value; break; default: e.Error = ErrorCode.ReadWriteDenied; break; } }
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 (value is string) { PHYReference = value.ToString(); } else { PHYReference = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString(); } } else if (index == 3) { List <GXDLMSPppSetupLcpOption> items = new List <GXDLMSPppSetupLcpOption>(); if (value is Object[]) { foreach (Object[] item in (Object[])value) { GXDLMSPppSetupLcpOption it = new GXDLMSPppSetupLcpOption(); it.Type = (GXDLMSPppSetupLcpOptionType)Convert.ToByte(item[0]); it.Length = Convert.ToByte(item[1]); it.Data = item[2]; items.Add(it); } } LCPOptions = items.ToArray(); } else if (index == 4) { List <GXDLMSPppSetupIPCPOption> items = new List <GXDLMSPppSetupIPCPOption>(); if (value is Object[]) { foreach (Object[] item in (Object[])value) { GXDLMSPppSetupIPCPOption it = new GXDLMSPppSetupIPCPOption(); it.Type = (GXDLMSPppSetupIPCPOptionType)Convert.ToByte(item[0]); it.Length = Convert.ToByte(item[1]); it.Data = item[2]; items.Add(it); } } IPCPOptions = items.ToArray(); } else if (index == 5) { UserName = (byte[])((Object[])value)[0]; Password = (byte[])((Object[])value)[1]; } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
static public object ConvertFromDLMS(object data, DataType from, DataType type, bool arrayAsString) { if (type == DataType.Array) { return(data); } if (type == DataType.None) { if (arrayAsString && data != null && data.GetType().IsArray) { data = GXHelpers.GetArrayAsString(data); } return(data); } //Show Octet string... if (from == DataType.OctetString && type == DataType.OctetString) { if (data is byte[]) { string str = ""; byte[] arr = (byte[])data; if (arr.Length == 0) { data = string.Empty; } else { foreach (byte it in arr) { str += it.ToString() + "."; } data = str.Substring(0, str.Length - 1); } } } //Convert DLMS octect string to Windows string. else if (from == DataType.OctetString && type == DataType.String) { if (data is string) { return(data); } else if (data is byte[]) { byte[] arr = (byte[])data; data = System.Text.Encoding.ASCII.GetString(arr); } } //Convert DLMS date time to Windows Time. else if (type == DataType.DateTime) { if (data is byte[]) { if (((byte[])data).Length == 5) { return(GXDLMSClient.ChangeType((byte[])data, DataType.Date)); } return(GXDLMSClient.ChangeType((byte[])data, DataType.DateTime)); } return(data); } //Convert DLMS date time to Windows Date. else if (type == DataType.Date) { if (data is DateTime) { return(data); } if (data is string) { return(data); } if (!data.GetType().IsArray || ((Array)data).Length < 5) { throw new Exception("DateTime conversion failed. Invalid DLMS format."); } return(GXDLMSClient.ChangeType((byte[])data, DataType.Date)); } //Convert DLMS date time to Windows Time. else if (type == DataType.Time) { if (data is byte[]) { return(GXDLMSClient.ChangeType((byte[])data, type)); } return(data); } else if (data is byte[]) { if (type == DataType.String) { data = System.Text.Encoding.ASCII.GetString((byte[])data); } else { data = ToHexString(data); } } else if (data is Array) { data = ArrayToString(data); } return(data); }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { switch (e.Index) { case 1: LogicalName = GXCommon.ToLogicalName(e.Value); break; case 2: if (e.Value is byte[]) { Operator = ASCIIEncoding.ASCII.GetString((byte[])e.Value); } else { Operator = (string)e.Value; } break; case 3: Status = (GsmStatus)(byte)e.Value; break; case 4: CircuitSwitchStatus = (GsmCircuitSwitchStatus)(byte)e.Value; break; case 5: PacketSwitchStatus = (GsmPacketSwitchStatus)(byte)e.Value; break; case 6: if (e.Value != null) { object[] tmp = (object[])e.Value; CellInfo.CellId = Convert.ToUInt32(tmp[0]); CellInfo.LocationId = (UInt16)tmp[1]; CellInfo.SignalQuality = (byte)tmp[2]; CellInfo.Ber = (byte)tmp[3]; if (Version > 0) { CellInfo.MobileCountryCode = (UInt16)tmp[4]; CellInfo.MobileNetworkCode = (UInt16)tmp[5]; CellInfo.ChannelNumber = (UInt32)tmp[6]; } } break; case 7: AdjacentCells.Clear(); if (e.Value != null) { foreach (object it in (object[])e.Value) { object[] tmp = (object[])it; AdjacentCell ac = new Objects.AdjacentCell(); ac.CellId = Convert.ToUInt32(tmp[0]); ac.SignalQuality = (byte)tmp[1]; AdjacentCells.Add(ac); } } break; case 8: if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } CaptureTime = (GXDateTime)e.Value; break; default: e.Error = ErrorCode.ReadWriteDenied; break; } }
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).ToString(); } } else if (e.Index == 2) { ListeningWindow.Clear(); if (e.Value is Object[]) { foreach (object it in e.Value as Object[]) { Object[] tmp = it as Object[]; GXDateTime start = GXDLMSClient.ChangeType((byte[])tmp[0], DataType.DateTime) as GXDateTime; GXDateTime end = GXDLMSClient.ChangeType((byte[])tmp[1], DataType.DateTime) as GXDateTime; ListeningWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end)); } } } else if (e.Index == 3) { if (e.Value is Object[]) { List <string> tmp = new List <string>(); foreach (object it in e.Value as Object[]) { tmp.Add(ASCIIEncoding.ASCII.GetString((byte[])it)); } AllowedSenders = tmp.ToArray(); } else { AllowedSenders = new string[0]; } } else if (e.Index == 4) { SendersAndActions.Clear(); if (e.Value is Object[]) { foreach (object it in e.Value as Object[]) { Object[] tmp = it as Object[]; string id = ASCIIEncoding.ASCII.GetString((byte[])tmp[0]); Object[] tmp2 = tmp[1] as Object[]; /*TODO: * KeyValuePair<int, GXDLMSScriptAction> executed_script = new KeyValuePair<int, GXDLMSScriptAction>(Convert.ToInt32(tmp2[1], tmp2[2])); * SendersAndActions.Add(new KeyValuePair<string, KeyValuePair<int, GXDLMSScriptAction>>(id, tmp[1] as GXDateTime)); * */ } } } else { e.Error = ErrorCode.ReadWriteDenied; } }
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) { ObjectType ot = (ObjectType)Convert.ToInt16(((object[])e.Value)[0]); string ln = GXDLMSClient.ChangeType((byte[])((object[])e.Value)[1], DataType.OctetString, settings.UseUtc2NormalTime).ToString(); int attIndex = Convert.ToInt32(((object[])e.Value)[2]); MonitoredValue = settings.Objects.FindByLN(ot, ln); MonitoredAttributeIndex = attIndex; } else if (e.Index == 3) { ThresholdActive = e.Value; } else if (e.Index == 4) { ThresholdNormal = e.Value; } else if (e.Index == 5) { ThresholdEmergency = e.Value; } else if (e.Index == 6) { MinOverThresholdDuration = Convert.ToUInt32(e.Value); } else if (e.Index == 7) { MinUnderThresholdDuration = Convert.ToUInt32(e.Value); } else if (e.Index == 8) { object[] tmp = (object[])e.Value; EmergencyProfile.ID = (UInt16)tmp[0]; EmergencyProfile.ActivationTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])tmp[1], DataType.DateTime, settings.UseUtc2NormalTime); EmergencyProfile.Duration = (UInt32)tmp[2]; } else if (e.Index == 9) { List <UInt16> list = new List <UInt16>(); if (e.Value != null) { foreach (object it in (object[])e.Value) { list.Add(Convert.ToUInt16(it)); } } EmergencyProfileGroupIDs = list.ToArray(); } else if (e.Index == 10) { EmergencyProfileActive = Convert.ToBoolean(e.Value); } else if (e.Index == 11) { object[] tmp = (object[])e.Value; object[] tmp1 = (object[])tmp[0]; object[] tmp2 = (object[])tmp[1]; ActionOverThreshold.LogicalName = GXDLMSClient.ChangeType((byte[])tmp1[0], DataType.OctetString, settings.UseUtc2NormalTime).ToString(); ActionOverThreshold.ScriptSelector = Convert.ToUInt16(tmp1[1]); ActionUnderThreshold.LogicalName = GXDLMSClient.ChangeType((byte[])tmp2[0], DataType.OctetString, settings.UseUtc2NormalTime).ToString(); ActionUnderThreshold.ScriptSelector = Convert.ToUInt16(tmp2[1]); } else { e.Error = ErrorCode.ReadWriteDenied; } }
void UpdateData(DataTable dt) { Standard standard = Standard.DLMS; if (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. } } } } } }
private static void HanleSetRequestWithDataBlock(GXDLMSSettings settings, GXDLMSServer server, GXByteBuffer data, GXDLMSLNParameters p, GXByteBuffer replyData, GXDLMSTranslatorStructure xml) { GXDataInfo reply = new GXDataInfo(); reply.xml = xml; byte lastBlock = data.GetUInt8(); p.multipleBlocks = lastBlock == 0; uint blockNumber = data.GetUInt32(); if (xml == null && blockNumber != settings.BlockIndex) { Debug.WriteLine("HanleSetRequestWithDataBlock failed. Invalid block number. " + settings.BlockIndex + "/" + blockNumber); p.status = (byte)ErrorCode.DataBlockNumberInvalid; } else { settings.IncreaseBlockIndex(); int size = GXCommon.GetObjectCount(data); int realSize = data.Size - data.Position; if (size != realSize) { Debug.WriteLine("HanleSetRequestWithDataBlock failed. Invalid block size."); p.status = (byte)ErrorCode.DataBlockUnavailable; } if (xml != null) { xml.AppendStartTag(TranslatorTags.DataBlock); xml.AppendLine(TranslatorTags.LastBlock, "Value", xml.IntegerToHex(lastBlock, 2)); xml.AppendLine(TranslatorTags.BlockNumber, "Value", xml.IntegerToHex(blockNumber, 8)); xml.AppendLine(TranslatorTags.RawData, "Value", data.RemainingHexString(false)); xml.AppendEndTag(TranslatorTags.DataBlock); return; } server.transaction.data.Set(data); //If all data is received. if (!p.multipleBlocks) { try { object value = GXCommon.GetData(settings, server.transaction.data, reply); if (value is byte[]) { DataType dt = (server.transaction.targets[0].Target as IGXDLMSBase).GetDataType(server.transaction.targets[0].Index); if (dt != DataType.None && dt != DataType.OctetString) { value = GXDLMSClient.ChangeType((byte[])value, dt, settings.UseUtc2NormalTime); } } server.transaction.targets[0].Value = value; server.NotifyWrite(server.transaction.targets); if (!server.transaction.targets[0].Handled && !p.multipleBlocks) { (server.transaction.targets[0].Target as IGXDLMSBase).SetValue(settings, server.transaction.targets[0]); server.NotifyPostWrite(server.transaction.targets); } } catch (Exception) { p.status = (byte)ErrorCode.HardwareFault; } finally { server.transaction = null; } settings.ResetBlockIndex(); } } p.multipleBlocks = true; }
private static void HandleSetRequestNormal(GXDLMSSettings settings, GXDLMSServer server, GXByteBuffer data, byte type, GXDLMSLNParameters p, GXByteBuffer replyData, GXDLMSTranslatorStructure xml) { object value = null; GXDataInfo reply = new GXDataInfo(); // CI ObjectType ci = (ObjectType)data.GetUInt16(); byte[] ln = new byte[6]; data.Get(ln); // Attribute index. byte index = data.GetUInt8(); // Get Access Selection. data.GetUInt8(); if (xml != null) { AppendAttributeDescriptor(xml, (int)ci, ln, index); xml.AppendStartTag(TranslatorTags.Value); GXDataInfo di = new GXDataInfo(); di.xml = xml; value = GXCommon.GetData(settings, data, di); if (!di.Complete) { value = GXCommon.ToHex(data.Data, false, data.Position, data.Size - data.Position); } else if (value is byte[]) { value = GXCommon.ToHex((byte[])value, false); } xml.AppendEndTag(TranslatorTags.Value); return; } if (type == 2) { p.multipleBlocks = data.GetUInt8() == 0; uint blockNumber = data.GetUInt32(); if (blockNumber != settings.BlockIndex) { Debug.WriteLine("HandleSetRequest failed. Invalid block number. " + settings.BlockIndex + "/" + blockNumber); p.status = (byte)ErrorCode.DataBlockNumberInvalid; return; } settings.IncreaseBlockIndex(); int size = GXCommon.GetObjectCount(data); int realSize = data.Size - data.Position; if (size != realSize) { Debug.WriteLine("HandleSetRequest failed. Invalid block size."); p.status = (byte)ErrorCode.DataBlockUnavailable; return; } } if (!p.multipleBlocks) { settings.ResetBlockIndex(); value = GXCommon.GetData(settings, data, reply); } GXDLMSObject obj = settings.Objects.FindByLN(ci, GXCommon.ToLogicalName(ln)); if (obj == null) { obj = server.NotifyFindObject(ci, 0, GXCommon.ToLogicalName(ln)); } // If target is unknown. if (obj == null) { // Device reports a undefined object. p.status = (byte)ErrorCode.UndefinedObject; } else { ValueEventArgs e = new ValueEventArgs(server, obj, index, 0, null); e.InvokeId = p.InvokeId; AccessMode am = server.NotifyGetAttributeAccess(e); // If write is denied. if (am != AccessMode.Write && am != AccessMode.ReadWrite) { //Read Write denied. p.status = (byte)ErrorCode.ReadWriteDenied; } else { try { if (value is byte[]) { DataType dt = (obj as IGXDLMSBase).GetDataType(index); if (dt != DataType.None && dt != DataType.OctetString && dt != DataType.Structure) { value = GXDLMSClient.ChangeType((byte[])value, dt, settings.UseUtc2NormalTime); } } e.Value = value; ValueEventArgs[] list = new ValueEventArgs[] { e }; if (p.multipleBlocks) { server.transaction = new GXDLMSLongTransaction(list, Command.GetRequest, data); } server.NotifyWrite(list); if (e.Error != 0) { p.status = (byte)e.Error; } else if (!e.Handled && !p.multipleBlocks) { (obj as IGXDLMSBase).SetValue(settings, e); server.NotifyPostWrite(list); if (e.Error != 0) { p.status = (byte)e.Error; } } p.InvokeId = e.InvokeId; } catch (Exception) { p.status = (byte)ErrorCode.HardwareFault; } } } }
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 (Scaler != 1) { try { CurrentAverageValue = Convert.ToDouble(value) * Scaler; } catch (Exception) { //Sometimes scaler is set for wrong Object type. CurrentAverageValue = value; } } else { CurrentAverageValue = value; } } else if (index == 3) { if (Scaler != 1) { try { LastAverageValue = Convert.ToDouble(value) * Scaler; } catch (Exception) { //Sometimes scaler is set for wrong Object type. LastAverageValue = value; } } else { LastAverageValue = value; } } else if (index == 4) { if (value == null) { Scaler = 1; Unit = Unit.None; } else { object[] arr = (object[])value; if (arr.Length != 2) { throw new Exception("setValue failed. Invalid scaler unit value."); } _scaler = Convert.ToInt32(arr[0]); Unit = (Unit)Convert.ToInt32(arr[1]); } } else if (index == 5) { Status = Convert.ToInt32(value); } else if (index == 6) { if (value == null) { CaptureTime = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } CaptureTime = (GXDateTime)value; } } else if (index == 7) { if (value == null) { StartTimeCurrent = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } StartTimeCurrent = (GXDateTime)value; } } else if (index == 8) { Period = Convert.ToUInt32(value); } else if (index == 9) { NumberOfPeriods = Convert.ToUInt16(value); } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
byte[][] IGXDLMSBase.Invoke(object sender, int index, Object parameters) { DateTime tm = this.Time.Value; // Resets the value to the default value. // The default value is an instance specific constant. if (index == 1) { int minutes = tm.Minute; if (minutes < 8) { minutes = 0; } else if (minutes < 23) { minutes = 15; } else if (minutes < 38) { minutes = 30; } else if (minutes < 53) { minutes = 45; } else { minutes = 0; tm = tm.AddHours(1); } tm = tm.AddMinutes(-tm.Minute + minutes); tm = tm.AddSeconds(-tm.Second); tm = tm.AddMilliseconds(-tm.Millisecond); this.Time.Value = tm; } // Sets the meter’s time to the nearest minute. else if (index == 3) { tm = this.Time.Value; int s = tm.Second; if (s > 30) { tm = tm.AddMinutes(1); } tm = tm.AddSeconds(-tm.Second); tm = tm.AddMilliseconds(-tm.Millisecond); this.Time.Value = tm; } // Presets the time to a new value (preset_time) and defines // avalidity_interval within which the new time can be activated. else if (index == 5) { GXDateTime presetTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])((Object[])parameters)[0], DataType.DateTime); GXDateTime validityIntervalStart = (GXDateTime)GXDLMSClient.ChangeType((byte[])((Object[])parameters)[1], DataType.DateTime); GXDateTime validityIntervalEnd = (GXDateTime)GXDLMSClient.ChangeType((byte[])((Object[])parameters)[2], DataType.DateTime); this.Time.Value = presetTime.Value; } // Shifts the time. else if (index == 6) { int shift = Convert.ToInt32(parameters); tm = tm.AddSeconds(shift); this.Time.Value = tm; } else { throw new ArgumentException("Invoke failed. Invalid attribute index."); } return(null); }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { LogicalName = GXCommon.ToLogicalName(e.Value); } else if (e.Index == 2) { if (Scaler != 1 && e.Value != null && !e.User) { try { if (settings.IsServer) { CurrentAverageValue = e.Value; } else { CurrentAverageValue = Convert.ToDouble(e.Value) * Scaler; } } catch (Exception) { //Sometimes scaler is set for wrong Object type. CurrentAverageValue = e.Value; } } else { CurrentAverageValue = e.Value; } } else if (e.Index == 3) { if (Scaler != 1 && e.Value != null && !e.User) { try { SetDataType(e.Index, GXCommon.GetDLMSDataType(e.Value.GetType())); if (settings.IsServer) { LastAverageValue = e.Value; } else { LastAverageValue = Convert.ToDouble(e.Value) * Scaler; } } catch (Exception) { //Sometimes scaler is set for wrong Object type. LastAverageValue = e.Value; } } else { LastAverageValue = e.Value; } } else if (e.Index == 4) { if (e.Value == null) { Scaler = 1; Unit = Unit.None; } else { List <object> arr; if (e.Value is List <object> ) { arr = (List <object>)e.Value; } else { arr = new List <object>((object[])e.Value); } if (arr.Count != 2) { throw new Exception("setValue failed. Invalid scaler unit value."); } scaler = Convert.ToInt32(arr[0]); Unit = (Unit)Convert.ToInt32(arr[1]); } } else if (e.Index == 5) { Status = Convert.ToInt32(e.Value); } else if (e.Index == 6) { if (e.Value == null) { CaptureTime = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } CaptureTime = (GXDateTime)e.Value; } } else if (e.Index == 7) { if (e.Value == null) { StartTimeCurrent = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } StartTimeCurrent = (GXDateTime)e.Value; } } else if (e.Index == 8) { Period = Convert.ToUInt32(e.Value); } else if (e.Index == 9) { NumberOfPeriods = Convert.ToUInt16(e.Value); } else { e.Error = ErrorCode.ReadWriteDenied; } }
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 (value == null) { Time = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } Time = (GXDateTime)value; } } else if (index == 3) { TimeZone = Convert.ToInt32(value); } else if (index == 4) { Status = (ClockStatus)Convert.ToInt32(value); } else if (index == 5) { if (value == null) { Begin = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } Begin = (GXDateTime)value; } } else if (index == 6) { if (value == null) { End = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } End = (GXDateTime)value; } } else if (index == 7) { Deviation = Convert.ToInt32(value); } else if (index == 8) { Enabled = Convert.ToBoolean(value); } else if (index == 9) { ClockBase = (ClockBase)Convert.ToInt32(value); } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { switch (e.Index) { case 1: LogicalName = GXCommon.ToLogicalName(e.Value); break; case 2: AccountStatus = (AccountStatus)((object[])e.Value)[0]; PaymentMode = (PaymentMode)((object[])e.Value)[1]; break; case 3: CurrentCreditInUse = (byte)e.Value; break; case 4: CurrentCreditStatus = (AccountCreditStatus)Convert.ToByte(e.Value); break; case 5: AvailableCredit = (int)e.Value; break; case 6: AmountToClear = (int)e.Value; break; case 7: ClearanceThreshold = (int)e.Value; break; case 8: AggregatedDebt = (int)e.Value; break; case 9: CreditReferences.Clear(); if (e.Value != null) { foreach (object it in (object[])e.Value) { CreditReferences.Add(GXCommon.ToLogicalName(it)); } } break; case 10: ChargeReferences.Clear(); if (e.Value != null) { foreach (object it in (object[])e.Value) { ChargeReferences.Add(GXCommon.ToLogicalName(it)); } } break; case 11: CreditChargeConfigurations.Clear(); if (e.Value != null) { foreach (object[] it in (object[])e.Value) { GXCreditChargeConfiguration item = new GXCreditChargeConfiguration(); item.CreditReference = GXCommon.ToLogicalName(it[0]); item.ChargeReference = GXCommon.ToLogicalName(it[1]); item.CollectionConfiguration = (CreditCollectionConfiguration)Convert.ToByte(it[2]); CreditChargeConfigurations.Add(item); } } break; case 12: TokenGatewayConfigurations.Clear(); if (e.Value != null) { foreach (object[] it in (object[])e.Value) { GXTokenGatewayConfiguration item = new GXTokenGatewayConfiguration(); item.CreditReference = GXCommon.ToLogicalName(it[0]); item.TokenProportion = (byte)it[1]; TokenGatewayConfigurations.Add(item); } } break; case 13: if (e.Value == null) { AccountActivationTime = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } if (e.Value is GXDateTime) { AccountActivationTime = (GXDateTime)e.Value; } } break; case 14: if (e.Value == null) { AccountClosureTime = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } if (e.Value is GXDateTime) { AccountClosureTime = (GXDateTime)e.Value; } } break; case 15: object[] tmp = (object[])e.Value; Currency.Name = (string)tmp[0]; Currency.Scale = (sbyte)tmp[1]; Currency.Unit = (Currency)tmp[2]; break; case 16: LowCreditThreshold = (int)e.Value; break; case 17: NextCreditAvailableThreshold = (int)e.Value; break; case 18: MaxProvision = (UInt16)e.Value; break; case 19: MaxProvisionPeriod = (int)e.Value; break; default: e.Error = ErrorCode.ReadWriteDenied; break; } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { switch (e.Index) { case 1: LogicalName = GXCommon.ToLogicalName(e.Value); break; case 2: Token = (byte[])e.Value; break; case 3: if (e.Value is byte[]) { Time = (GXDateTime)GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings != null && settings.UseUtc2NormalTime); } else if (e.Value is string) { Time = new GXDateTime((string)e.Value); } else { Time = (GXDateTime)e.Value; } break; case 4: Descriptions.Clear(); if (e.Value != null) { foreach (object it in (IEnumerable <object>)e.Value) { Descriptions.Add(ASCIIEncoding.ASCII.GetString((byte[])it)); } } break; case 5: DeliveryMethod = (TokenDelivery)Convert.ToByte(e.Value); break; case 6: if (e.Value != null) { List <object> arr; if (e.Value is List <object> ) { arr = (List <object>)e.Value; } else { arr = new List <object>((object[])e.Value); } StatusCode = (TokenStatusCode)Convert.ToInt32(arr[0]); DataValue = Convert.ToString(arr[1]); } else { StatusCode = TokenStatusCode.FormatOk; DataValue = ""; } break; default: e.Error = ErrorCode.ReadWriteDenied; break; } }
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) { if (e.Value is string) { this.DataLinkLayerReference = e.Value.ToString(); } else { this.DataLinkLayerReference = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString(); } } else if (e.Index == 3) { IPAddress = new System.Net.IPAddress(BitConverter.GetBytes(Convert.ToUInt32(e.Value))).ToString(); } else if (e.Index == 4) { List <uint> data = new List <uint>(); if (e.Value != null) { if (e.Value is Object[]) { foreach (object it in (Object[])e.Value) { data.Add(Convert.ToUInt16(it)); } } else if (e.Value is UInt16[]) { //Some meters are returning wrong data here. foreach (UInt16 it in (UInt16[])e.Value) { data.Add(it); } } } MulticastIPAddress = data.ToArray(); } else if (e.Index == 5) { List <GXDLMSIp4SetupIpOption> data = new List <GXDLMSIp4SetupIpOption>(); if (e.Value != null) { foreach (object[] it in (Object[])e.Value) { GXDLMSIp4SetupIpOption item = new GXDLMSIp4SetupIpOption(); item.Type = (Ip4SetupIpOptionType)Convert.ToInt32(it[0]); item.Length = Convert.ToByte(it[1]); item.Data = (byte[])it[2]; data.Add(item); } } IPOptions = data.ToArray(); } else if (e.Index == 6) { SubnetMask = Convert.ToUInt32(e.Value); } else if (e.Index == 7) { GatewayIPAddress = Convert.ToUInt32(e.Value); } else if (e.Index == 8) { UseDHCP = Convert.ToBoolean(e.Value); } else if (e.Index == 9) { PrimaryDNSAddress = Convert.ToUInt32(e.Value); } else if (e.Index == 10) { SecondaryDNSAddress = Convert.ToUInt32(e.Value); } else { e.Error = ErrorCode.ReadWriteDenied; } }
///<summary> /// Handle write request. ///</summary> public static void HandleWriteRequest(GXDLMSSettings settings, GXDLMSServer server, GXByteBuffer data, GXByteBuffer replyData, GXDLMSTranslatorStructure xml) { //Return error if connection is not established. if (xml == null && !settings.Connected) { replyData.Add(GXDLMSServer.GenerateConfirmedServiceError(ConfirmedServiceError.InitiateError, ServiceError.Service, (byte)Service.Unsupported)); return; } short type; object value; // Get object count. List <GXSNInfo> targets = new List <GXSNInfo>(); int cnt = GXCommon.GetObjectCount(data); if (xml != null) { xml.AppendStartTag(Command.WriteRequest); xml.AppendStartTag( TranslatorTags.ListOfVariableAccessSpecification, "Qty", xml.IntegerToHex(cnt, 2)); if (xml.OutputType == TranslatorOutputType.StandardXml) { xml.AppendStartTag( TranslatorTags.VariableAccessSpecification); } } GXByteBuffer results = new GXByteBuffer((ushort)cnt); for (int pos = 0; pos != cnt; ++pos) { type = data.GetUInt8(); if (type == (byte)VariableAccessSpecification.VariableName) { int sn = data.GetUInt16(); if (xml != null) { xml.AppendLine( (int)Command.WriteRequest << 8 | (int)VariableAccessSpecification.VariableName, "Value", xml.IntegerToHex(sn, 4)); } else { GXSNInfo info = FindSNObject(server, sn); targets.Add(info); // If target is unknown. if (info == null) { // Device reports a undefined object. results.SetUInt8(ErrorCode.UndefinedObject); } else { results.SetUInt8(ErrorCode.Ok); } } } else if (type == (byte)VariableAccessSpecification.WriteDataBlockAccess) { HandleReadDataBlockAccess(settings, server, Command.WriteResponse, data, cnt, replyData, xml); if (xml == null) { return; } } else { // Device reports a HW error. results.SetUInt8(ErrorCode.HardwareFault); } } if (xml != null) { if (xml.OutputType == TranslatorOutputType.StandardXml) { xml.AppendEndTag(TranslatorTags.VariableAccessSpecification); } xml.AppendEndTag( TranslatorTags.ListOfVariableAccessSpecification); } // Get data count. cnt = GXCommon.GetObjectCount(data); GXDataInfo di = new GXDataInfo(); di.xml = xml; if (xml != null) { xml.AppendStartTag(TranslatorTags.ListOfData, "Qty", xml.IntegerToHex(cnt, 2)); } for (int pos = 0; pos != cnt; ++pos) { di.Clear(); if (xml != null) { if (xml.OutputType == TranslatorOutputType.StandardXml) { xml.AppendStartTag(Command.WriteRequest, SingleReadResponse.Data); } value = GXCommon.GetData(settings, data, di); if (!di.Complete) { value = GXCommon.ToHex(data.Data, false, data.Position, data.Size - data.Position); xml.AppendLine( GXDLMS.DATA_TYPE_OFFSET + (int)di.Type, "Value", value.ToString()); } if (xml.OutputType == TranslatorOutputType.StandardXml) { xml.AppendEndTag(Command.WriteRequest, SingleReadResponse.Data); } GXCommon.GetData(settings, data, di); } else if (results.GetUInt8(pos) == 0) { // If object has found. GXSNInfo target = targets[pos]; value = GXCommon.GetData(settings, data, di); if (value is byte[]) { DataType dt = target.Item.GetDataType(target.Index); if (dt != DataType.None && dt != DataType.OctetString) { value = GXDLMSClient.ChangeType((byte[])value, dt); } } ValueEventArgs e = new ValueEventArgs(server, target.Item, target.Index, 0, null); AccessMode am = server.NotifyGetAttributeAccess(e); // If write is denied. if (am != AccessMode.Write && am != AccessMode.ReadWrite) { results.SetUInt8((byte)pos, (byte)ErrorCode.ReadWriteDenied); } else { e.Value = value; server.NotifyWrite(new ValueEventArgs[] { e }); if (e.Error != 0) { results.SetUInt8((byte)pos, (byte)e.Error); } else if (!e.Handled) { (target.Item as IGXDLMSBase).SetValue(settings, e); server.NotifyPostWrite(new ValueEventArgs[] { e }); } } } } if (xml != null) { xml.AppendEndTag(TranslatorTags.ListOfData); xml.AppendEndTag(Command.WriteRequest); return; } GenerateWriteResponse(settings, results, replyData); }
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) { ObjectList.Clear(); if (e.Value != null) { foreach (Object[] item in (Object[])e.Value) { ObjectType type = (ObjectType)Convert.ToInt32(item[0]); int version = Convert.ToInt32(item[1]); String ln = GXDLMSObject.ToLogicalName((byte[])item[2]); GXDLMSObject obj = null; if (settings.Objects != null) { obj = settings.Objects.FindByLN(type, ln); } if (obj == null) { obj = Gurux.DLMS.GXDLMSClient.CreateObject(type); obj.LogicalName = ln; obj.Version = version; } //Unknown objects are not shown. if (obj is IGXDLMSBase && item[3] != null) { UpdateAccessRights(obj, (Object[])item[3]); ObjectList.Add(obj); } } } } else if (e.Index == 3) { if (e.Value != null) { ClientSAP = Convert.ToByte(((Object[])e.Value)[0]); ServerSAP = Convert.ToUInt16(((Object[])e.Value)[1]); } } else if (e.Index == 4) { //Value of the object identifier encoded in BER if (e.Value is byte[]) { GXByteBuffer arr = new GXByteBuffer(e.Value as byte[]); if (arr.GetUInt8(0) == 0x60) { ApplicationContextName.JointIsoCtt = 0; ++arr.Position; ApplicationContextName.Country = 0; ++arr.Position; ApplicationContextName.CountryName = 0; ++arr.Position; ApplicationContextName.IdentifiedOrganization = arr.GetUInt8(); ApplicationContextName.DlmsUA = arr.GetUInt8(); ApplicationContextName.ApplicationContext = arr.GetUInt8(); ApplicationContextName.ContextId = arr.GetUInt8(); } else { //Get Tag and Len. if (arr.GetUInt8() != (int)BerType.Integer && arr.GetUInt8() != 7) { throw new ArgumentOutOfRangeException(); } //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } ApplicationContextName.JointIsoCtt = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } ApplicationContextName.Country = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x12) { throw new ArgumentOutOfRangeException(); } ApplicationContextName.CountryName = arr.GetUInt16(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } ApplicationContextName.IdentifiedOrganization = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } ApplicationContextName.DlmsUA = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } ApplicationContextName.ApplicationContext = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } ApplicationContextName.ContextId = arr.GetUInt8(); } } else if (e.Value != null) { Object[] arr = (Object[])e.Value; ApplicationContextName.JointIsoCtt = Convert.ToByte(arr[0]); ApplicationContextName.Country = Convert.ToByte(arr[1]); ApplicationContextName.CountryName = Convert.ToUInt16(arr[2]); ApplicationContextName.IdentifiedOrganization = Convert.ToByte(arr[3]); ApplicationContextName.DlmsUA = Convert.ToByte(arr[4]); ApplicationContextName.ApplicationContext = Convert.ToByte(arr[5]); ApplicationContextName.ContextId = Convert.ToByte(arr[6]); } } else if (e.Index == 5) { if (e.Value != null) { Object[] arr = (Object[])e.Value; GXByteBuffer bb = new GXByteBuffer(); GXCommon.SetBitString(bb, arr[0]); bb.SetUInt8(0, 0); XDLMSContextInfo.Conformance = (Conformance)bb.GetUInt32(); XDLMSContextInfo.MaxReceivePduSize = Convert.ToUInt16(arr[1]); XDLMSContextInfo.MaxSendPpuSize = Convert.ToUInt16(arr[2]); XDLMSContextInfo.DlmsVersionNumber = Convert.ToByte(arr[3]); XDLMSContextInfo.QualityOfService = Convert.ToSByte(arr[4]); XDLMSContextInfo.CypheringInfo = (byte[])arr[5]; } } else if (e.Index == 6) { //Value of the object identifier encoded in BER if (e.Value is byte[]) { GXByteBuffer arr = new GXByteBuffer(e.Value as byte[]); if (arr.GetUInt8(0) == 0x60) { AuthenticationMechanismName.JointIsoCtt = 0; ++arr.Position; AuthenticationMechanismName.Country = 0; ++arr.Position; AuthenticationMechanismName.CountryName = 0; ++arr.Position; AuthenticationMechanismName.IdentifiedOrganization = arr.GetUInt8(); AuthenticationMechanismName.DlmsUA = arr.GetUInt8(); AuthenticationMechanismName.AuthenticationMechanismName = arr.GetUInt8(); AuthenticationMechanismName.MechanismId = (Authentication)arr.GetUInt8(); } else { //Get Tag and Len. if (arr.GetUInt8() != (int)BerType.Integer && arr.GetUInt8() != 7) { throw new ArgumentOutOfRangeException(); } //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } AuthenticationMechanismName.JointIsoCtt = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } AuthenticationMechanismName.Country = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x12) { throw new ArgumentOutOfRangeException(); } AuthenticationMechanismName.CountryName = arr.GetUInt16(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } AuthenticationMechanismName.IdentifiedOrganization = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } AuthenticationMechanismName.DlmsUA = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } AuthenticationMechanismName.AuthenticationMechanismName = arr.GetUInt8(); //Get tag if (arr.GetUInt8() != 0x11) { throw new ArgumentOutOfRangeException(); } AuthenticationMechanismName.MechanismId = (Authentication)arr.GetUInt8(); } } else if (e.Value != null) { Object[] arr = (Object[])e.Value; AuthenticationMechanismName.JointIsoCtt = Convert.ToByte(arr[0]); AuthenticationMechanismName.Country = Convert.ToByte(arr[1]); AuthenticationMechanismName.CountryName = Convert.ToUInt16(arr[2]); AuthenticationMechanismName.IdentifiedOrganization = Convert.ToByte(arr[3]); AuthenticationMechanismName.DlmsUA = Convert.ToByte(arr[4]); AuthenticationMechanismName.AuthenticationMechanismName = Convert.ToByte(arr[5]); AuthenticationMechanismName.MechanismId = (Authentication)Convert.ToByte(arr[6]); } } else if (e.Index == 7) { Secret = (byte[])e.Value; } else if (e.Index == 8) { if (e.Value == null) { AssociationStatus = AssociationStatus.NonAssociated; } else { AssociationStatus = (AssociationStatus)Convert.ToInt32(e.Value); } } else if (e.Index == 9) { SecuritySetupReference = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, false).ToString(); } else { e.Error = ErrorCode.ReadWriteDenied; } }
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) { Scripts.Clear(); //Fix Xemex bug here. //Xemex meters do not return array as they shoul be according standard. if (e.Value is Object[] && ((Object[])e.Value).Length != 0) { if (((Object[])e.Value)[0] is Object[]) { foreach (Object[] item in (Object[])e.Value) { GXDLMSScript script = new GXDLMSScript(); script.Id = Convert.ToInt32(item[0]); Scripts.Add(script); foreach (Object[] arr in (Object[])item[1]) { GXDLMSScriptAction it = new GXDLMSScriptAction(); it.Type = (ScriptActionType)Convert.ToInt32(arr[0]); ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]); String ln = GXDLMSClient.ChangeType((byte[])arr[2], DataType.OctetString, settings.UseUtc2NormalTime).ToString(); it.Target = settings.Objects.FindByLN(ot, ln); if (it.Target == null) { #pragma warning disable CS0618 it.ObjectType = (ObjectType)Convert.ToInt32(arr[1]); it.LogicalName = GXDLMSClient.ChangeType((byte[])arr[2], DataType.OctetString, settings.UseUtc2NormalTime).ToString(); #pragma warning restore CS0618 } it.Index = Convert.ToInt32(arr[3]); it.Parameter = arr[4]; script.Actions.Add(it); } } } else //Read Xemex meter here. { GXDLMSScript script = new GXDLMSScript(); script.Id = Convert.ToInt32(((Object[])e.Value)[0]); Scripts.Add(script); Object[] arr = (Object[])((Object[])e.Value)[1]; GXDLMSScriptAction it = new GXDLMSScriptAction(); it.Type = (ScriptActionType)Convert.ToInt32(arr[0]); ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]); String ln = GXDLMSClient.ChangeType((byte[])arr[2], DataType.OctetString, settings.UseUtc2NormalTime).ToString(); it.Target = settings.Objects.FindByLN(ot, ln); if (it.Target == null) { #pragma warning disable CS0618 it.ObjectType = (ObjectType)Convert.ToInt32(arr[1]); it.LogicalName = GXDLMSClient.ChangeType((byte[])arr[2], DataType.OctetString, settings.UseUtc2NormalTime).ToString(); #pragma warning restore CS0618 } it.Index = Convert.ToInt32(arr[3]); it.Parameter = arr[4]; script.Actions.Add(it); } } } else { e.Error = ErrorCode.ReadWriteDenied; } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { LogicalName = GXCommon.ToLogicalName(e.Value); } else if (e.Index == 2) { if (e.Value is string) { this.DataLinkLayerReference = e.Value.ToString(); } else { this.DataLinkLayerReference = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString(); } } else if (e.Index == 3) { AddressConfigMode = (AddressConfigMode)Convert.ToInt32(e.Value); } else if (e.Index == 4) { List <IPAddress> data = new List <IPAddress>(); if (e.Value != null) { foreach (object it in (object[])e.Value) { data.Add(new IPAddress((byte[])it)); } } UnicastIPAddress = data.ToArray(); } else if (e.Index == 5) { List <IPAddress> data = new List <IPAddress>(); if (e.Value != null) { foreach (object it in (object[])e.Value) { data.Add(new IPAddress((byte[])it)); } } MulticastIPAddress = data.ToArray(); } else if (e.Index == 6) { List <IPAddress> data = new List <IPAddress>(); if (e.Value != null) { foreach (object it in (object[])e.Value) { data.Add(new IPAddress((byte[])it)); } } GatewayIPAddress = data.ToArray(); } else if (e.Index == 7) { if (e.Value == null || ((byte[])e.Value).Length == 0) { PrimaryDNSAddress = null; } else { PrimaryDNSAddress = new IPAddress((byte[])e.Value); } } else if (e.Index == 8) { if (e.Value == null || ((byte[])e.Value).Length == 0) { SecondaryDNSAddress = null; } else { SecondaryDNSAddress = new IPAddress((byte[])e.Value); } } else if (e.Index == 9) { TrafficClass = Convert.ToByte(e.Value); } else if (e.Index == 10) { List <GXNeighborDiscoverySetup> data = new List <GXNeighborDiscoverySetup>(); if (e.Value != null) { foreach (object it in (object[])e.Value) { object[] tmp = (object[])it; GXNeighborDiscoverySetup v = new GXNeighborDiscoverySetup(); v.MaxRetry = Convert.ToByte(tmp[0]); v.RetryWaitTime = Convert.ToUInt16(tmp[1]); v.SendPeriod = Convert.ToUInt32(tmp[2]); data.Add(v); } } NeighborDiscoverySetup = data.ToArray(); } else { e.Error = ErrorCode.ReadWriteDenied; } }
byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e) { DateTimeOffset tm = this.Time.Value; // Resets the value to the default value. // The default value is an instance specific constant. if (e.Index == 1) { int minutes = tm.Minute; if (minutes < 8) { minutes = 0; } else if (minutes < 23) { minutes = 15; } else if (minutes < 38) { minutes = 30; } else if (minutes < 53) { minutes = 45; } else { minutes = 0; tm = tm.AddHours(1); } tm = tm.AddMinutes(-tm.Minute + minutes); tm = tm.AddSeconds(-tm.Second); tm = tm.AddMilliseconds(-tm.Millisecond); this.Time.Value = tm; } // Sets the meter's time to the nearest minute. else if (e.Index == 3) { tm = this.Time.Value; int s = tm.Second; if (s > 30) { tm = tm.AddMinutes(1); } tm = tm.AddSeconds(-tm.Second); tm = tm.AddMilliseconds(-tm.Millisecond); this.Time.Value = tm; } // Presets the time to a new value (preset_time) and defines // avalidity_interval within which the new time can be activated. else if (e.Index == 5) { GXDateTime presetTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])((List <object>)e.Parameters)[0], DataType.DateTime, settings.UseUtc2NormalTime); GXDateTime validityIntervalStart = (GXDateTime)GXDLMSClient.ChangeType((byte[])((List <object>)e.Parameters)[1], DataType.DateTime, settings.UseUtc2NormalTime); GXDateTime validityIntervalEnd = (GXDateTime)GXDLMSClient.ChangeType((byte[])((List <object>)e.Parameters)[2], DataType.DateTime, settings.UseUtc2NormalTime); this.Time.Value = presetTime.Value; } // Shifts the time. else if (e.Index == 6) { int shift = Convert.ToInt32(e.Parameters); tm = tm.AddSeconds(shift); this.Time.Value = tm; } else { e.Error = ErrorCode.ReadWriteDenied; } return(null); }
private void SetBuffer(GXDLMSSettings settings, ValueEventArgs e) { List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > cols = null; if (e.Parameters is List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > ) { cols = (List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> >)e.Parameters; } if (cols == null) { cols = CaptureObjects; } if (e.Value != null && (e.Value as List <object>).Count != 0) { int index2 = 0; DateTime lastDate = DateTime.MinValue; foreach (List <object> t in (e.Value as List <object>)) { List <object> row = new List <object>(); foreach (object it in t) { if (it is GXStructure) { row.Add((List <object>)it); } else if (it is GXArray) { row.AddRange((List <object>)it); } else { row.Add(it); } } if (cols.Count != 0) { if (row.Count != cols.Count) { throw new Exception("The number of columns does not match."); } for (int pos = 0; pos != row.Count; ++pos) { if (cols == null) { index2 = 0; } else { index2 = cols[pos].Value.AttributeIndex; } DataType type; //Actaris SL 7000 and ACE 6000 returns 0. if (index2 > 0) { type = cols[pos].Key.GetUIDataType(index2); } else { type = DataType.None; } if (row[pos] is GXEnum) { row[pos] = Convert.ToByte(row[pos]); } else if (row[pos] is byte[]) { if (type != DataType.None && row[pos] is byte[]) { row[pos] = GXDLMSClient.ChangeType(row[pos] as byte[], type, settings.UseUtc2NormalTime); 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); } } else if (type == DataType.DateTime && row[pos] is UInt32) { row[pos] = GXDateTime.FromUnixTime(((UInt32)row[pos])); } if (cols[pos].Key is GXDLMSRegister && index2 == 2) { double scaler = (cols[pos].Key as GXDLMSRegister).Scaler; if (scaler != 1) { try { row[pos] = Convert.ToDouble(row[pos]) * scaler; } catch { //Skip error } } } else if (cols[pos].Key is GXDLMSDemandRegister && (index2 == 2 || index2 == 3)) { double scaler = (cols[pos].Key as GXDLMSDemandRegister).Scaler; if (scaler != 1) { try { row[pos] = Convert.ToDouble(row[pos]) * scaler; } catch { //Skip error } } } else if (cols[pos].Key is GXDLMSRegister && index2 == 3) { try { GXDLMSRegister r = new GXDLMSRegister(); ValueEventArgs v = new ValueEventArgs(r, 3, 0, null); v.Value = row[pos]; (r as IGXDLMSBase).SetValue(null, v); row[pos] = new object[] { r.Scaler, r.Unit }; } catch { //Skip error } } } } Buffer.Add(row.ToArray()); } EntriesInUse = Buffer.Count; } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { LogicalName = GXCommon.ToLogicalName(e.Value); } else if (e.Index == 2) { if (e.Value == null) { Time = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings != null && settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } if (e.Value is GXDateTime) { Time = (GXDateTime)e.Value; } else if (e.Value is String) { DateTime tm; if (!DateTime.TryParse((String)e.Value, out tm)) { Time = DateTime.ParseExact((String)e.Value, CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern, CultureInfo.CurrentUICulture); } else { Time = tm; } } else { Time = Convert.ToDateTime(e.Value); } } } else if (e.Index == 3) { TimeZone = Convert.ToInt32(e.Value); } else if (e.Index == 4) { Status = (ClockStatus)Convert.ToInt32(e.Value); } else if (e.Index == 5) { if (e.Value == null) { Begin = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } Begin = (GXDateTime)e.Value; } } else if (e.Index == 6) { if (e.Value == null) { End = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else if (e.Value is string) { e.Value = new GXDateTime((string)e.Value); } End = (GXDateTime)e.Value; } } else if (e.Index == 7) { Deviation = Convert.ToInt32(e.Value); } else if (e.Index == 8) { Enabled = Convert.ToBoolean(e.Value); if (settings != null && settings.IsServer) { if (Enabled) { Status |= ClockStatus.DaylightSavingActive; } else { Status &= ~ClockStatus.DaylightSavingActive; } } } else if (e.Index == 9) { ClockBase = (ClockBase)Convert.ToInt32(e.Value); } else { e.Error = ErrorCode.ReadWriteDenied; } }
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) { if (Scaler != 1) { try { Value = Convert.ToDouble(e.Value) * Scaler; } catch (Exception) { //Sometimes scaler is set for wrong Object type. Value = e.Value; } } else { Value = e.Value; } } else if (e.Index == 3) { if (e.Value == null) { Scaler = 1; Unit = Unit.None; } else { object[] arr = (object[])e.Value; if (arr.Length != 2) { throw new Exception("setValue failed. Invalid scaler unit value."); } scaler = Convert.ToInt32(arr[0]); Unit = (Unit)Convert.ToInt32(arr[1]); } } else if (e.Index == 4) { Status = e.Value; } else if (e.Index == 5) { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } //Actaris meters might return null. if (e.Value == null) { CaptureTime = new GXDateTime(); } else { CaptureTime = ((GXDateTime)e.Value).Value.LocalDateTime; } } else { e.Error = ErrorCode.ReadWriteDenied; } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { LogicalName = GXCommon.ToLogicalName(e.Value); } else if (e.Index == 2) { if (e.Value is byte[] v) { if (IsSec() || !GXByteBuffer.IsAsciiString(v)) { CalendarNameActive = GXCommon.ToHex(v, false); } else { CalendarNameActive = ASCIIEncoding.ASCII.GetString(v); } } else { CalendarNameActive = Convert.ToString(e.Value); } } else if (e.Index == 3) { SeasonProfileActive = SetSeasonProfile(settings, e.Value); } else if (e.Index == 4) { WeekProfileTableActive = SetWeekProfileTable(settings, e.Value); } else if (e.Index == 5) { DayProfileTableActive = SetDayProfileTable(settings, e.Value); } else if (e.Index == 6) { if (e.Value is byte[] v) { if (IsSec() || !GXByteBuffer.IsAsciiString(v)) { CalendarNamePassive = GXCommon.ToHex(v, false); } else { CalendarNamePassive = ASCIIEncoding.ASCII.GetString(v); } } else { CalendarNamePassive = Convert.ToString(e.Value); } } else if (e.Index == 7) { SeasonProfilePassive = SetSeasonProfile(settings, e.Value); } else if (e.Index == 8) { WeekProfileTablePassive = SetWeekProfileTable(settings, e.Value); } else if (e.Index == 9) { DayProfileTablePassive = SetDayProfileTable(settings, e.Value); } else if (e.Index == 10) { if (e.Value is byte[]) { Time = (GXDateTime)GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime); } else { Time = new GXDateTime(Convert.ToDateTime(e.Value)); } } else { e.Error = ErrorCode.ReadWriteDenied; } }