Exemple #1
0
        /// <summary>
        /// Read association view.
        /// </summary>
        public void GetAssociationView(bool useCache)
        {
            GXReplyData reply = new GXReplyData();

            ReadDataBlock(Client.GetObjectsRequest(), reply);
            Client.ParseObjects(reply.Data, true);
        }
Exemple #2
0
        /// <summary>
        /// Read Association View from the meter.
        /// </summary>
        public GXDLMSObjectCollection GetAssociationView()
        {
            GXReplyData reply = new GXReplyData();

            ReadDataBlock(Client.GetObjectsRequest(), reply);
            return(Client.ParseObjects(reply.Data, true));
        }
        /// <summary>
        /// Read association view.
        /// </summary>
        public bool GetAssociationView(string outputFile)
        {
            if (outputFile != null)
            {
                //Save Association view to the cache so it is not needed to retrieve every time.
                if (File.Exists(outputFile))
                {
                    try
                    {
                        Client.Objects.Clear();
                        Client.Objects.AddRange(GXDLMSObjectCollection.Load(outputFile));
                        return(false);
                    }
                    catch (Exception)
                    {
                        if (File.Exists(outputFile))
                        {
                            File.Delete(outputFile);
                        }
                    }
                }
            }
            GXReplyData reply = new GXReplyData();

            ReadDataBlock(Client.GetObjectsRequest(), reply);
            Client.ParseObjects(reply.Data, true);
            //Access rights must read differently when short Name referencing is used.
            if (!Client.UseLogicalNameReferencing)
            {
                GXDLMSAssociationShortName sn = (GXDLMSAssociationShortName)Client.Objects.FindBySN(0xFA00);
                if (sn != null && sn.Version > 0)
                {
                    Read(sn, 3);
                }
            }
            if (outputFile != null)
            {
                try
                {
                    Client.Objects.Save(outputFile, new GXXmlWriterSettings()
                    {
                        Values = false
                    });
                }
                catch (Exception)
                {
                    //It's OK if this fails.
                    return(false);
                }
            }
            return(true);
        }
        public GXDLMSObjectCollection GetObjects()
        {
            GXLogWriter.WriteLog("--- Collecting objects. ---");
            GXReplyData reply = new GXReplyData()
            {
            };

            try
            {
                ReadDataBlock(client.GetObjectsRequest(), "Collecting objects", 3, reply);
            }
            catch (Exception Ex)
            {
                throw new Exception("GetObjects failed. " + Ex.Message);
            }
            GXDLMSObjectCollection objs = client.ParseObjects(reply.Data, true);

            GXLogWriter.WriteLog("--- Collecting " + objs.Count.ToString() + " objects. ---");
            return(objs);
        }
Exemple #5
0
        /// <summary>
        /// Read association view.
        /// </summary>
        public void GetAssociationView(bool useCache)
        {
            if (useCache)
            {
                string      path       = GetCacheName();
                List <Type> extraTypes = new List <Type>(Gurux.DLMS.GXDLMSClient.GetObjectTypes());
                extraTypes.Add(typeof(GXDLMSAttributeSettings));
                extraTypes.Add(typeof(GXDLMSAttribute));
                XmlSerializer x = new XmlSerializer(typeof(GXDLMSObjectCollection), extraTypes.ToArray());
                //You can save association view, but make sure that it is not change.
                //Save Association view to the cache so it is not needed to retrieve every time.
                if (File.Exists(path))
                {
                    try
                    {
                        using (Stream stream = File.Open(path, FileMode.Open))
                        {
                            Console.WriteLine("Get available objects from the cache.");
                            Client.Objects.AddRange(x.Deserialize(stream) as GXDLMSObjectCollection);
                            stream.Close();
                        }
                        return;
                    }
                    catch (Exception ex)
                    {
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                        throw ex;
                    }
                }
            }
            GXReplyData reply = new GXReplyData();

            ReadDataBlock(Client.GetObjectsRequest(), reply);
            Client.ParseObjects(reply.Data, true);
        }
Exemple #6
0
        /// <summary>
        /// Read association view.
        /// </summary>
        public void GetAssociationView(bool useCache)
        {
            if (useCache)
            {
                string      path       = GetCacheName();
                List <Type> extraTypes = new List <Type>(Gurux.DLMS.GXDLMSClient.GetObjectTypes());
                extraTypes.Add(typeof(GXDLMSAttributeSettings));
                extraTypes.Add(typeof(GXDLMSAttribute));
                XmlSerializer x = new XmlSerializer(typeof(GXDLMSObjectCollection), extraTypes.ToArray());
                //You can save association view, but make sure that it is not change.
                //Save Association view to the cache so it is not needed to retrieve every time.
                if (File.Exists(path))
                {
                    try
                    {
                        using (Stream stream = File.Open(path, FileMode.Open))
                        {
                            Console.WriteLine("Get available objects from the cache.");
                            Client.Objects.AddRange(x.Deserialize(stream) as GXDLMSObjectCollection);
                            stream.Close();
                        }
                        return;
                    }
                    catch (Exception ex)
                    {
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                        throw ex;
                    }
                }
            }
            GXReplyData reply = new GXReplyData();

            ReadDataBlock(Client.GetObjectsRequest(), reply);
            Client.ParseObjects(reply.Data, true);
            //Access rights must read differently when short Name referencing is used.
            if (!Client.UseLogicalNameReferencing)
            {
                GXDLMSAssociationShortName sn = (GXDLMSAssociationShortName)Client.Objects.FindBySN(0xFA00);
                if (sn.Version > 0)
                {
                    Read(sn, 3);
                }
                else
                {
                    //LGZ is using "0.0.127.0.0.0" to mark inactive object that might cause problems.
                    //Skip them.
                    int cnt = Client.Objects.Count;
                    for (int pos = 0; pos < cnt; ++pos)
                    {
                        if (Client.Objects[pos].LogicalName == "0.0.127.0.0.0")
                        {
                            Client.Objects.RemoveAt(pos);
                            --pos;
                            --cnt;
                        }
                    }
                }
            }
        }