Exemple #1
0
        public void Remove(TIRAPOPCDevice item)
        {
            bool successed = false;

            do
            {
                successed = items.Remove(item);
            } while (successed);
        }
Exemple #2
0
        public void Add(TIRAPOPCDevice item)
        {
            if (item != null)
            {
                items.Add(item);

                foreach (KeyValuePair <string, TIRAPOPCTag> idxItem in item.TagIndex)
                {
                    indexTags.Add(idxItem.Key, idxItem.Value);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 根据 TRESPOPCServerTagList 对象创建 TIRAPOPCDevice 实例
        /// </summary>
        /// <param name="item">TRESPOPCServerTagList 对象</param>
        /// <returns></returns>
        public static TIRAPOPCDevice CreateInstance(TRESPOPCServerTagList item)
        {
            if (item == null)
            {
                return(null);
            }

            TIRAPOPCDevice rlt =
                TGeneric.Mapper <TIRAPOPCDevice, TRESPOPCServerTagList>(item);

            if (rlt.TagList != "")
            {
                XmlDocument xml = new XmlDocument();
                try { xml.LoadXml(rlt.TagList); }
                catch { return(rlt); }

                XmlNode root = xml.SelectSingleNode("Parameters");
                if (root != null)
                {
                    foreach (XmlNode child in root.ChildNodes)
                    {
                        TIRAPOPCTag tag =
                            TIRAPOPCTag.CreateInstance(child);
                        if (tag != null)
                        {
                            tag.Device = rlt;
                            rlt.Tags.Add(tag);
                            rlt.TagIndex.Add(
                                string.Format(
                                    "{0}.{1}",
                                    rlt.ServerName,
                                    tag.TagName),
                                tag);
                        }
                    }
                }
            }

            return(rlt);
        }
Exemple #4
0
        /// <summary>
        /// 获取数据库中注册的 OPC 设备及标签
        /// </summary>
        /// <param name="communityID">社区标识</param>
        /// <param name="sysLogID">系统登录标识</param>
        public void GetDevices(int communityID, long sysLogID)
        {
            TGetOPCServerTagList exchange = new TGetOPCServerTagList(webAPIUrl, contentType, clientID);

            exchange.Request =
                new TREQOPCServerTagList()
            {
                CommunityID = communityID,
                SysLogID    = sysLogID,
            };

            if (!exchange.Do())
            {
                Debug.WriteLine(
                    string.Format(
                        "({0}){1}",
                        exchange.Error.ErrCode,
                        exchange.Error.ErrText),
                    "");
            }
            else
            {
                devices.Clear();
                foreach (TRESPOPCServerTagList item in exchange.Response.Rows)
                {
                    TIRAPOPCDevice device =
                        TIRAPOPCDevice.CreateInstance(item);
                    if (device != null)
                    {
                        devices.Add(device);
                    }
                }
                devices.IndexTags =
                    devices.IndexTags.OrderBy(
                        p => p.Key).ToDictionary(
                        p => p.Key, o => o.Value);
            }
        }