예제 #1
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         CommunicationSpeed = (BaudRate)Convert.ToInt32(e.Value);
     }
     else if (e.Index == 3)
     {
         InitialisationStrings = null;
         if (e.Value != null)
         {
             List <GXDLMSModemInitialisation> items = new List <GXDLMSModemInitialisation>();
             foreach (object tmp in (IEnumerable <object>)e.Value)
             {
                 List <object> it;
                 if (tmp is List <object> )
                 {
                     it = (List <object>)tmp;
                 }
                 else
                 {
                     it = new List <object>((object[])tmp);
                 }
                 GXDLMSModemInitialisation item = new GXDLMSModemInitialisation();
                 item.Request  = ASCIIEncoding.ASCII.GetString((byte[])it[0]);
                 item.Response = ASCIIEncoding.ASCII.GetString((byte[])it[1]);
                 if (it.Count > 2)
                 {
                     item.Delay = Convert.ToUInt16(it[2]);
                 }
                 items.Add(item);
             }
             InitialisationStrings = items.ToArray();
         }
     }
     else if (e.Index == 4)
     {
         ModemProfile = null;
         if (e.Value != null)
         {
             List <string> items = new List <string>();
             foreach (object it in (IEnumerable <object>)e.Value)
             {
                 items.Add(GXDLMSClient.ChangeType((byte[])it, DataType.String, false).ToString().Trim());
             }
             ModemProfile = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #2
0
 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)
         {
             SetDataType(2, GXCommon.GetDLMSDataType(e.Value.GetType()));
             try
             {
                 if (settings != null && settings.IsServer)
                 {
                     Value = e.Value;
                 }
                 else
                 {
                     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]) & 0xFF);
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #3
0
        ///<summary>
        /// Handle Event Notification.
        ///</summary>
        internal static void HandleEventNotification(GXDLMSSettings settings, GXReplyData reply, List <KeyValuePair <GXDLMSObject, int> > list)
        {
            reply.Time = DateTime.MinValue;
            int len = reply.Data.GetUInt8();

            byte[] tmp = null;
            // If date time is given.
            if (len != 0)
            {
                tmp = new byte[len];
                reply.Data.Get(tmp);
                reply.Time = (GXDateTime)GXDLMSClient.ChangeType(tmp, DataType.DateTime, settings.UseUtc2NormalTime);
            }
            if (reply.Xml != null)
            {
                reply.Xml.AppendStartTag(Command.EventNotification);
                if (reply.Time != DateTime.MinValue)
                {
                    reply.Xml.AppendComment(Convert.ToString(reply.Time));
                    reply.Xml.AppendLine(TranslatorTags.Time, null,
                                         GXCommon.ToHex(tmp, false));
                }
            }
            int ci = reply.Data.GetUInt16();

            byte[] ln = new byte[6];
            reply.Data.Get(ln);
            byte index = reply.Data.GetUInt8();

            if (reply.Xml != null)
            {
                AppendAttributeDescriptor(reply.Xml, ci, ln, index);
                reply.Xml.AppendStartTag(TranslatorTags.AttributeValue);
            }
            GXDataInfo di = new GXDataInfo();

            di.xml = reply.Xml;
            object value = GXCommon.GetData(settings, reply.Data, di);

            if (reply.Xml != null)
            {
                reply.Xml.AppendEndTag(TranslatorTags.AttributeValue);
                reply.Xml.AppendEndTag(Command.EventNotification);
            }
            else
            {
                GXDLMSObject obj = settings.Objects.FindByLN((ObjectType)ci, GXCommon.ToLogicalName(ln));
                if (obj != null)
                {
                    ValueEventArgs v = new ValueEventArgs(obj, index, 0, null);
                    v.Value = value;
                    (obj as IGXDLMSBase).SetValue(settings, v);
                    list.Add(new KeyValuePair <GXDLMSObject, int>(obj, index));
                }
            }
        }
 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)
         {
             DefaultBaud = BaudRate.Baudrate300;
         }
         else
         {
             DefaultBaud = (BaudRate)Convert.ToInt32(e.Value);
         }
     }
     else if (e.Index == 3)
     {
         if (e.Value == null)
         {
             AvailableBaud = BaudRate.Baudrate300;
         }
         else
         {
             AvailableBaud = (BaudRate)Convert.ToInt32(e.Value);
         }
     }
     else if (e.Index == 4)
     {
         if (e.Value == null)
         {
             AddressState = AddressState.None;
         }
         else
         {
             AddressState = (AddressState)Convert.ToInt32(e.Value);
         }
     }
     else if (e.Index == 5)
     {
         if (e.Value == null)
         {
             BusAddress = 0;
         }
         else
         {
             BusAddress = Convert.ToInt32(e.Value);
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #5
0
        private static void SetCaptureObjects(GXDLMSSettings settings, List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > list, object[] array)
        {
            GXDLMSConverter c = null;

            list.Clear();
            try
            {
                if (array != null)
                {
                    foreach (object it in array)
                    {
                        object[] tmp = it as object[];
                        if (tmp.Length != 4)
                        {
                            throw new GXDLMSException("Invalid structure format.");
                        }
                        int v = Convert.ToInt16(tmp[0]);
                        if (Enum.GetName(typeof(ObjectType), v) == null)
                        {
                            list.Clear();
                            return;
                        }
                        ObjectType type           = (ObjectType)v;
                        string     ln             = GXCommon.ToLogicalName((byte[])tmp[1]);
                        int        attributeIndex = Convert.ToInt16(tmp[2]);
                        //If profile generic selective access is used.
                        if (attributeIndex < 0)
                        {
                            attributeIndex = 2;
                        }
                        int          dataIndex = Convert.ToInt16(tmp[3]);
                        GXDLMSObject obj       = null;
                        if (settings != null && settings.Objects != null)
                        {
                            obj = settings.Objects.FindByLN(type, ln);
                        }
                        if (obj == null)
                        {
                            obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0);
                            if (c == null)
                            {
                                c = new GXDLMSConverter();
                            }
                            c.UpdateOBISCodeInformation(obj);
                        }
                        list.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(attributeIndex, dataIndex)));
                    }
                }
            }
            catch (Exception ex)
            {
                list.Clear();
                throw ex;
            }
        }
예제 #6
0
        /// <summary>
        /// Get country spesific OBIS codes.
        /// </summary>
        /// <param name="standard">Used standard.</param>
        /// <returns>Collection for special OBIC codes.</returns>
        public static GXObisCode[] GetObjects(Standard standard)
        {
            List <GXObisCode> codes = new List <GXObisCode>();

#if !WINDOWS_UWP
            string[] rows;
#if __MOBILE__
            if (standard == Standard.Italy)
            {
                rows = Resources.Italy.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else if (standard == Standard.India)
            {
                rows = Resources.India.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else if (standard == Standard.SaudiArabia)
            {
                rows = Resources.SaudiArabia.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                return(new GXObisCode[0]);
            }
#else
            if (standard == Standard.Italy)
            {
                rows = Gurux.DLMS.Properties.Resources.Italy.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else if (standard == Standard.India)
            {
                rows = Gurux.DLMS.Properties.Resources.India.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else if (standard == Standard.SaudiArabia)
            {
                rows = Gurux.DLMS.Properties.Resources.SaudiArabia.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                return(new GXObisCode[0]);
            }
#endif //!__MOBILE__
            foreach (string it in rows)
            {
                string[]   items   = it.Split(new char[] { ';' });
                ObjectType ot      = (ObjectType)int.Parse(items[0]);
                string     ln      = GXCommon.ToLogicalName(GXCommon.LogicalNameToBytes(items[1]));
                int        version = int.Parse(items[2]);
                string     desc    = items[3];
                GXObisCode code    = new GXObisCode(ln, ot, desc);
                code.Version = version;
                codes.Add(code);
            }
#endif
            return(codes.ToArray());
        }
예제 #7
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         PHYReference = GXCommon.ToLogicalName(e.Value);
     }
     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)
     {
         if (e.Value != null)
         {
             UserName = (byte[])((Object[])e.Value)[0];
             Password = (byte[])((Object[])e.Value)[1];
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #8
0
 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)
         {
             string ln = GXCommon.ToLogicalName(((object[])e.Value)[0]);
             Target = (GXDLMSScriptTable)settings.Objects.FindByLN(ObjectType.ScriptTable, ln);
             if (Target == null)
             {
                 Target = new GXDLMSScriptTable(ln);
             }
             ExecutedScriptSelector = Convert.ToUInt16(((object[])e.Value)[1]);
         }
         else
         {
             Target = null;
             ExecutedScriptSelector = 0;
         }
     }
     else if (e.Index == 3)
     {
         Type = (SingleActionScheduleType)Convert.ToInt32(e.Value);
     }
     else if (e.Index == 4)
     {
         ExecutionTime = null;
         if (e.Value != null)
         {
             List <GXDateTime> items = new List <GXDateTime>();
             foreach (object[] it in (object[])e.Value)
             {
                 GXDateTime time = (GXDateTime)GXDLMSClient.ChangeType((byte[])it[0], DataType.Time, settings.UseUtc2NormalTime);
                 time.Skip &= ~(DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day | DateTimeSkips.DayOfWeek);
                 GXDateTime date = (GXDateTime)GXDLMSClient.ChangeType((byte[])it[1], DataType.Date, settings.UseUtc2NormalTime);
                 date.Skip &= ~(DateTimeSkips.Hour | DateTimeSkips.Minute | DateTimeSkips.Second | DateTimeSkips.Ms);
                 GXDateTime tmp = new DLMS.GXDateTime(date);
                 tmp.Value = tmp.Value.AddHours(time.Value.Hour);
                 tmp.Value = tmp.Value.AddMinutes(time.Value.Minute);
                 tmp.Value = tmp.Value.AddSeconds(time.Value.Second);
                 tmp.Skip  = date.Skip | time.Skip;
                 items.Add(tmp);
             }
             ExecutionTime = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
        private static void SetCaptureObjects(GXDLMSProfileGeneric parent, GXDLMSSettings settings, List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > list, IEnumerable <object> array)
        {
            GXDLMSConverter c = null;

            try
            {
                foreach (object it in array)
                {
                    List <object> tmp;
                    if (it is List <object> )
                    {
                        tmp = (List <object>)it;
                    }
                    else
                    {
                        tmp = new List <object>((object[])it);
                    }
                    if (tmp.Count != 4)
                    {
                        throw new GXDLMSException("Invalid structure format.");
                    }
                    int v = Convert.ToInt16(tmp[0]);
                    if (Enum.GetName(typeof(ObjectType), v) == null)
                    {
                        list.Clear();
                        return;
                    }
                    ObjectType   type           = (ObjectType)v;
                    string       ln             = GXCommon.ToLogicalName((byte[])tmp[1]);
                    int          attributeIndex = Convert.ToInt16(tmp[2]);
                    int          dataIndex      = Convert.ToInt16(tmp[3]);
                    GXDLMSObject obj            = null;
                    if (settings != null && settings.Objects != null)
                    {
                        obj = settings.Objects.FindByLN(type, ln);
                    }
                    //Create a new instance to avoid circular references.
                    if (obj == null || obj == parent)
                    {
                        obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0);
                        if (c == null)
                        {
                            c = new GXDLMSConverter(settings == null ? Standard.DLMS : settings.Standard);
                        }
                        c.UpdateOBISCodeInformation(obj);
                    }
                    list.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(attributeIndex, dataIndex)));
                }
            }
            catch (Exception)
            {
                list.Clear();
            }
        }
예제 #10
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         List <GXDLMSObjectDefinition> items = new List <GXDLMSObjectDefinition>();
         if (e.Value != null)
         {
             foreach (Object[] it in (Object[])e.Value)
             {
                 GXDLMSObjectDefinition item = new GXDLMSObjectDefinition();
                 item.ObjectType  = (ObjectType)Convert.ToInt32(it[0]);
                 item.LogicalName = GXCommon.ToLogicalName((byte[])it[1]);
                 items.Add(item);
             }
         }
         RegisterAssignment = items.ToArray();
     }
     else if (e.Index == 3)
     {
         MaskList.Clear();
         if (e.Value != null)
         {
             foreach (Object[] it in (Object[])e.Value)
             {
                 List <byte> index_list = new List <byte>();
                 foreach (byte b in (Object[])it[1])
                 {
                     index_list.Add(b);
                 }
                 MaskList.Add(new KeyValuePair <byte[], byte[]>((byte[])it[0], index_list.ToArray()));
             }
         }
     }
     else if (e.Index == 4)
     {
         if (e.Value == null)
         {
             ActiveMask = null;
         }
         else
         {
             ActiveMask = (byte[])e.Value;
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #11
0
        ParsePush(Object[] data)
        {
            int          index;
            GXDLMSObject obj;
            object       value;
            DataType     dt;
            List <KeyValuePair <GXDLMSObject, int> > items = new List <KeyValuePair <GXDLMSObject, int> >();

            if (data != null)
            {
                GXDLMSConverter        c       = new GXDLMSConverter();
                GXDLMSObjectCollection objects = new GXDLMSObjectCollection();
                foreach (Object it in (Object[])data[0])
                {
                    Object[] tmp     = (Object[])it;
                    int      classID = ((UInt16)(tmp[0])) & 0xFFFF;
                    if (classID > 0)
                    {
                        GXDLMSObject comp;
                        comp = this.Objects.FindByLN((ObjectType)classID, GXCommon.ToLogicalName(tmp[1] as byte[]));
                        if (comp == null)
                        {
                            comp = GXDLMSClient.CreateDLMSObject(classID, 0, 0, tmp[1], null);
                            c.UpdateOBISCodeInformation(comp);
                            objects.Add(comp);
                        }
                        if ((comp is IGXDLMSBase))
                        {
                            items.Add(new KeyValuePair <GXDLMSObject, int>(comp, (sbyte)tmp[2]));
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine(string.Format("Unknown object : {0} {1}",
                                                                             classID, GXCommon.ToLogicalName((byte[])tmp[1])));
                        }
                    }
                }
                for (int pos = 0; pos < data.Length; ++pos)
                {
                    obj   = items[pos].Key as GXDLMSObject;
                    value = data[pos];
                    index = items[pos].Value;
                    if (value is byte[] && (dt = obj.GetUIDataType(index)) != DataType.None)
                    {
                        value = GXDLMSClient.ChangeType(value as byte[], dt, Settings.UseUtc2NormalTime);
                    }
                    ValueEventArgs e = new ValueEventArgs(Settings, obj, index, 0, null);
                    e.Value = value;
                    (obj as IGXDLMSBase).SetValue(Settings, e);
                }
            }
            return(items);
        }
예제 #12
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         NodeId = (byte)e.Value;
     }
     else if (e.Index == 3)
     {
         SubnetId = (byte)e.Value;
     }
     else if (e.Index == 4)
     {
         if (e.Value is string)
         {
             DomainId = e.Value.ToString();
         }
         else
         {
             DomainId = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, false).ToString();
         }
     }
     else if (e.Index == 6)
     {
         if (e.Value is string)
         {
             ProgramId = e.Value.ToString();
         }
         else
         {
             ProgramId = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, false).ToString();
         }
     }
     else if (e.Index == 7)
     {
         if (e.Value is string)
         {
             UniqueNodeId = e.Value.ToString();
         }
         else
         {
             UniqueNodeId = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
        public GXDLMSObject FindByLN(ObjectType type, byte[] ln)
        {
            string name = GXCommon.ToLogicalName(ln);

            foreach (GXDLMSObject it in this)
            {
                if ((type == ObjectType.None || it.ObjectType == type) && it.LogicalName.Trim() == name)
                {
                    return(it);
                }
            }
            return(null);
        }
예제 #14
0
 private static void AppendMethodDescriptor(GXDLMSTranslatorStructure xml, int ci, byte[] ln, byte attributeIndex)
 {
     xml.AppendStartTag(TranslatorTags.MethodDescriptor);
     if (xml.Comments)
     {
         xml.AppendComment(((ObjectType)ci).ToString());
     }
     xml.AppendLine(TranslatorTags.ClassId, "Value", xml.IntegerToHex((int)ci, 4));
     xml.AppendComment(GXCommon.ToLogicalName(ln));
     xml.AppendLine(TranslatorTags.InstanceId, "Value", GXCommon.ToHex(ln, false));
     xml.AppendLine(TranslatorTags.MethodId, "Value", xml.IntegerToHex(attributeIndex, 2));
     xml.AppendEndTag(TranslatorTags.MethodDescriptor);
 }
예제 #15
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         PlcSignalQualityStatus = (byte)e.Value;
     }
     else if (e.Index == 3)
     {
         TransceiverState = (byte)e.Value;
     }
     else if (e.Index == 4)
     {
         ReceivedMessageStatus = (byte)e.Value;
     }
     else if (e.Index == 5)
     {
         NoReceiveBuffer = (UInt16)e.Value;
     }
     else if (e.Index == 6)
     {
         TransmitNoData = (UInt16)e.Value;
     }
     else if (e.Index == 7)
     {
         UnexpectedPlcCommandCount = (UInt16)e.Value;
     }
     else if (e.Index == 8)
     {
         BacklogOverflows = (UInt16)e.Value;
     }
     else if (e.Index == 9)
     {
         LateAck = (UInt16)e.Value;
     }
     else if (e.Index == 10)
     {
         FrequencyInvalid = (UInt16)e.Value;
     }
     else if (e.Index == 11)
     {
         PlcTestRate = (byte)e.Value;
     }
     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)
     {
         TransmissionErrors = (UInt16)e.Value;
     }
     else if (e.Index == 3)
     {
         TransmitFailure = (UInt16)e.Value;
     }
     else if (e.Index == 4)
     {
         TransmitRetries = (UInt16)e.Value;
     }
     else if (e.Index == 5)
     {
         ReceiveFull = (UInt16)e.Value;
     }
     else if (e.Index == 6)
     {
         LostMessages = (UInt16)e.Value;
     }
     else if (e.Index == 7)
     {
         MissedMessages = (UInt16)e.Value;
     }
     else if (e.Index == 8)
     {
         Layer2Received = (UInt16)e.Value;
     }
     else if (e.Index == 9)
     {
         Layer3Received = (UInt16)e.Value;
     }
     else if (e.Index == 10)
     {
         MessagesReceived = (UInt16)e.Value;
     }
     else if (e.Index == 11)
     {
         MessagesValidated = (UInt16)e.Value;
     }
     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)
     {
         CalendarName = ASCIIEncoding.ASCII.GetString((byte[])e.Value);
     }
     else if (e.Index == 3)
     {
         Enabled = Convert.ToBoolean(e.Value);
     }
     else if (e.Index == 4)
     {
         if (e.Value is object[])
         {
             object[] it = e.Value as object[];
             Plan.DefaultTariffBand = Convert.ToByte(it[0]);
             UpdateSeason(Plan.WinterSeason, (it[1] as object[])[0] as object[]);
             UpdateSeason(Plan.SummerSeason, (it[1] as object[])[1] as object[]);
             Plan.WeeklyActivation = (string)it[2];
             Plan.SpecialDays      = (UInt16[])it[3];
         }
     }
     else if (e.Index == 5)
     {
         if (e.Value is object[])
         {
             object[]   it   = e.Value as object[];
             GXDateTime time = (GXDateTime)GXDLMSClient.ChangeType((byte[])it[0], DataType.Time, settings.UseUtc2NormalTime);
             time.Skip &= ~(DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day | DateTimeSkips.DayOfWeek);
             GXDateTime date = (GXDateTime)GXDLMSClient.ChangeType((byte[])it[1], DataType.Date, settings.UseUtc2NormalTime);
             date.Skip           &= ~(DateTimeSkips.Hour | DateTimeSkips.Minute | DateTimeSkips.Second | DateTimeSkips.Ms);
             ActivationTime       = new DLMS.GXDateTime(date);
             ActivationTime.Value = ActivationTime.Value.AddHours(time.Value.Hour);
             ActivationTime.Value = ActivationTime.Value.AddMinutes(time.Value.Minute);
             ActivationTime.Value = ActivationTime.Value.AddSeconds(time.Value.Second);
             ActivationTime.Skip  = date.Skip | time.Skip;
         }
         else
         {
             ActivationTime = new GXDateTime(DateTime.MinValue);
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
 byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index != 1 && e.Index != 2)
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
     else
     {
         if (e.Index == 1)
         {
             List <object> tmp   = (List <object>)e.Parameters;
             ObjectType    type  = (ObjectType)Convert.ToUInt16(tmp[0]);
             string        ln    = GXCommon.ToLogicalName((byte[])tmp[1]);
             byte          index = Convert.ToByte(tmp[2]);
             foreach (GXDLMSTarget item in Parameters)
             {
                 if (item.Target.ObjectType == type && item.Target.LogicalName == ln && item.AttributeIndex == index)
                 {
                     Parameters.Remove(item);
                     break;
                 }
             }
             GXDLMSTarget it = new GXDLMSTarget();
             it.Target = settings.Objects.FindByLN(type, (byte[])tmp[1]);
             if (it.Target == null)
             {
                 it.Target             = GXDLMSClient.CreateObject(type);
                 it.Target.LogicalName = ln;
             }
             it.AttributeIndex = index;
             Parameters.Add(it);
         }
         else if (e.Index == 2)
         {
             List <object> tmp   = (List <object>)e.Parameters;
             ObjectType    ot    = (ObjectType)Convert.ToUInt16(tmp[0]);
             string        ln    = GXCommon.ToLogicalName((byte[])tmp[1]);
             byte          index = Convert.ToByte(tmp[2]);
             foreach (GXDLMSTarget item in Parameters)
             {
                 if (item.Target.ObjectType == ot && item.Target.LogicalName == ln && item.AttributeIndex == index)
                 {
                     Parameters.Remove(item);
                     break;
                 }
             }
         }
     }
     return(null);
 }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         Mode = (AutoConnectMode)Convert.ToInt32(e.Value);
     }
     else if (e.Index == 3)
     {
         Repetitions = Convert.ToInt32(e.Value);
     }
     else if (e.Index == 4)
     {
         RepetitionDelay = Convert.ToInt32(e.Value);
     }
     else if (e.Index == 5)
     {
         CallingWindow.Clear();
         if (e.Value != null)
         {
             foreach (Object[] item in (Object[])e.Value)
             {
                 GXDateTime start = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[0], DataType.DateTime, settings.UseUtc2NormalTime);
                 GXDateTime end   = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[1], DataType.DateTime, settings.UseUtc2NormalTime);
                 CallingWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end));
             }
         }
     }
     else if (e.Index == 6)
     {
         Destinations = null;
         if (e.Value != null)
         {
             List <string> items = new List <string>();
             foreach (byte[] item in (object[])e.Value)
             {
                 string it = GXDLMSClient.ChangeType(item, DataType.String, false).ToString();
                 items.Add(it);
             }
             Destinations = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #20
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         ImageBlockSize = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 3)
     {
         ImageTransferredBlocksStatus = (string)e.Value;
     }
     else if (e.Index == 4)
     {
         ImageFirstNotTransferredBlockNumber = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 5)
     {
         ImageTransferEnabled = Convert.ToBoolean(e.Value);
     }
     else if (e.Index == 6)
     {
         ImageTransferStatus = (ImageTransferStatus)Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 7)
     {
         ImageActivateInfo = null;
         List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>();
         if (e.Value != null)
         {
             foreach (Object it in (Object[])e.Value)
             {
                 GXDLMSImageActivateInfo item = new GXDLMSImageActivateInfo();
                 Object[] tmp = (Object[])it;
                 item.Size           = Convert.ToUInt32(tmp[0]);
                 item.Identification = ASCIIEncoding.ASCII.GetString((byte[])tmp[1]);
                 item.Signature      = ASCIIEncoding.ASCII.GetString((byte[])tmp[2]);
                 list.Add(item);
             }
         }
         ImageActivateInfo = list.ToArray();
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #21
0
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            switch (e.Index)
            {
            case 1:
                LogicalName = GXCommon.ToLogicalName(e.Value);
                break;

            case 2:
                Mode = (IecTwistedPairSetupMode)Convert.ToByte(e.Value);
                break;

            case 3:
                Speed = (BaudRate)Convert.ToByte(e.Value);
                break;

            case 4:
            {
                GXByteBuffer list = new GXByteBuffer();
                if (e.Value != null)
                {
                    foreach (object it in (List <object>)e.Value)
                    {
                        list.Add((byte)it);
                    }
                }
                PrimaryAddresses = list.Array();
                break;
            }

            case 5:
            {
                List <sbyte> list = new List <sbyte>();
                if (e.Value != null)
                {
                    foreach (object it in (List <object>)e.Value)
                    {
                        list.Add((sbyte)it);
                    }
                }
                Tabis = list.ToArray();
                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)
     {
         CommSpeed = (BaudRate)Convert.ToInt32(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #23
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         Value = e.Value;
     }
     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)
     {
         Entries = null;
         if (e.Value != null)
         {
             List <GXDLMSSpecialDay> items = new List <GXDLMSSpecialDay>();
             foreach (object tmp in (IEnumerable <object>)e.Value)
             {
                 List <object> item;
                 if (tmp is List <object> )
                 {
                     item = (List <object>)tmp;
                 }
                 else
                 {
                     item = new List <object>((object[])tmp);
                 }
                 GXDLMSSpecialDay it = new GXDLMSSpecialDay();
                 it.Index = Convert.ToUInt16(item[0]);
                 if (item[1] is GXDate)
                 {
                     it.Date = (GXDate)item[1];
                 }
                 else if (item[1] is byte[])
                 {
                     it.Date = (GXDate)GXDLMSClient.ChangeType((byte[])item[1], DataType.Date, settings.UseUtc2NormalTime);
                 }
                 else
                 {
                     throw new Exception("Invalid date.");
                 }
                 it.DayId = Convert.ToByte(item[2]);
                 items.Add(it);
             }
             Entries = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #25
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         MacAddress = GXCommon.ToHex((byte[])e.Value, true);
         MacAddress = MacAddress.Replace(' ', ':');
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #26
0
 byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         List <GXDLMSObjectDefinition> items = new List <GXDLMSObjectDefinition>();
         if (RegisterAssignment != null)
         {
             items.AddRange(RegisterAssignment);
         }
         GXDLMSObjectDefinition item = new GXDLMSObjectDefinition();
         item.ObjectType  = (ObjectType)Convert.ToInt32(((GXStructure)e.Parameters)[0]);
         item.LogicalName = GXCommon.ToLogicalName((byte[])((GXStructure)e.Parameters)[1]);
         items.Add(item);
         RegisterAssignment = items.ToArray();
     }
     else if (e.Index == 2)
     {
         int         index      = GetMaskIndex((byte[])((GXStructure)e.Parameters)[0]);
         List <byte> index_list = new List <byte>();
         foreach (byte b in (IEnumerable <object>)((GXStructure)e.Parameters)[1])
         {
             index_list.Add(b);
         }
         if (index == -1)
         {
             MaskList.Add(new KeyValuePair <byte[], byte[]>((byte[])((GXStructure)e.Parameters)[0], index_list.ToArray()));
         }
         else
         {
             MaskList.RemoveAt(index);
             MaskList.Insert(index, new KeyValuePair <byte[], byte[]>((byte[])((GXStructure)e.Parameters)[0], index_list.ToArray()));
         }
     }
     else if (e.Index == 3)
     {
         int index = GetMaskIndex((byte[])e.Parameters);
         if (index != -1)
         {
             MaskList.RemoveAt(index);
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
     return(null);
 }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         TxDataPacketCount = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 3)
     {
         RxDataPacketCount = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 4)
     {
         TxCmdPacketCount = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 5)
     {
         RxCmdPacketCount = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 6)
     {
         CSMAFailCount = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 7)
     {
         CSMANoAckCount = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 8)
     {
         BadCrcCount = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 9)
     {
         TxDataBroadcastCount = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 10)
     {
         RxDataBroadcastCount = Convert.ToUInt32(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #28
0
 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)
         {
             APN = e.Value.ToString();
         }
         else
         {
             APN = ASCIIEncoding.ASCII.GetString((byte[])e.Value);
         }
     }
     else if (e.Index == 3)
     {
         PINCode = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 4)
     {
         DefaultQualityOfService.Precedence   = DefaultQualityOfService.Delay = DefaultQualityOfService.Reliability = DefaultQualityOfService.PeakThroughput = DefaultQualityOfService.MeanThroughput = 0;
         RequestedQualityOfService.Precedence = RequestedQualityOfService.Delay = RequestedQualityOfService.Reliability = RequestedQualityOfService.PeakThroughput = RequestedQualityOfService.MeanThroughput = 0;
         if (e.Value != null)
         {
             List <object> tmp = (List <object>)e.Value;
             List <object> t   = (List <object>)tmp[0] as List <object>;
             DefaultQualityOfService.Precedence     = Convert.ToByte(t[0]);
             DefaultQualityOfService.Delay          = Convert.ToByte(t[1]);
             DefaultQualityOfService.Reliability    = Convert.ToByte(t[2]);
             DefaultQualityOfService.PeakThroughput = Convert.ToByte(t[3]);
             DefaultQualityOfService.MeanThroughput = Convert.ToByte(t[4]);
             t = (List <object>)tmp[1] as List <object>;
             RequestedQualityOfService.Precedence     = Convert.ToByte(t[0]);
             RequestedQualityOfService.Delay          = Convert.ToByte(t[1]);
             RequestedQualityOfService.Reliability    = Convert.ToByte(t[2]);
             RequestedQualityOfService.PeakThroughput = Convert.ToByte(t[3]);
             RequestedQualityOfService.MeanThroughput = Convert.ToByte(t[4]);
         }
     }
     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:
                MaximumOctetsUiPdu = Convert.ToUInt16(e.Value);
                break;

            default:
                e.Error = ErrorCode.ReadWriteDenied;
                break;
            }
        }
예제 #30
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         Mode = (AutoAnswerMode)Convert.ToInt32(e.Value);
     }
     else if (e.Index == 3)
     {
         ListeningWindow.Clear();
         if (e.Value != null)
         {
             foreach (object[] item in (object[])e.Value)
             {
                 GXDateTime start = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[0], DataType.DateTime, settings.UseUtc2NormalTime);
                 GXDateTime end   = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[1], DataType.DateTime, settings.UseUtc2NormalTime);
                 ListeningWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end));
             }
         }
     }
     else if (e.Index == 4)
     {
         Status = (AutoAnswerStatus)Convert.ToInt32(e.Value);
     }
     else if (e.Index == 5)
     {
         NumberOfCalls = Convert.ToInt32(e.Value);
     }
     else if (e.Index == 6)
     {
         NumberOfRingsInListeningWindow = NumberOfRingsOutListeningWindow = 0;
         if (e.Value != null)
         {
             NumberOfRingsInListeningWindow  = Convert.ToInt32(((object[])e.Value)[0]);
             NumberOfRingsOutListeningWindow = Convert.ToInt32(((object[])e.Value)[1]);
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }