Пример #1
0
        public List <string> ScanOPCDa(string host, bool isClean = false)
        {
            if (isClean)
            {
                hostCollection.Clear();
            }

            List <string> retValue = new List <string>();

            try
            {
                OpcServerDescription[] opcServers = serverEnumerator.Enumerate(host, OpcServerCategory.OpcDaServer10,
                                                                               OpcServerCategory.OpcDaServer20,
                                                                               OpcServerCategory.OpcDaServer30);

                string[] serviceList = opcServers.Select(a => a.ProgId).ToArray();
                if (serviceList.Any())
                {
                    if (hostCollection.Any(a => { return(a.Host == host); }))
                    {
                        HostCollection item = hostCollection.Where(a => { return(a.Host == host); })
                                              .FirstOrDefault();
                        var exceptList = item.ServiceIds.Except(serviceList);
                        if (exceptList.Any())
                        {
                            item.ServiceIds.AddRange(exceptList);
                        }
                    }
                    else
                    {
                        hostCollection.Add(new HostCollection()
                        {
                            Host = host, ServiceIds = serviceList.ToList()
                        });
                    }

                    TreeNode opcdaNode = OPCDAViewHelper.GetRootNode();
                    TreeNode hostNode  = OPCDAViewHelper.AddNode(opcdaNode, host, host);
                    foreach (string progId in serviceList)
                    {
                        OPCDAViewHelper.AddNode(hostNode, progId, progId);
                    }
                }

                return(opcServers.Select(a => a.ProgId).ToList());
            }
            catch (Exception)
            {
                return(retValue);
            }
        }
Пример #2
0
        public string StartMonitoringItems(string host, string serviceProgId, TreeNode groupNode, int interval, int count)
        {
            OpcDaService server   = GetOpcDaService(host, serviceProgId);
            string       groupKey = OPCDAViewHelper.Key(groupNode.Text);

            if (server == null)
            {
                LogHelper.Log("StartMonitoringItems  is null");
                return(null);
            }

            // if (server.OpcDaGroupS.Count == 0 || !server.OpcDaGroupS.ContainsKey(groupKey))
            // {
            LogHelper.Log("StartMonitoringItems  is host opcda://" + host + "/" + serviceProgId);
            AddGroup(server, groupKey, groupNode, interval, count);
            // }

            return(groupKey);
        }