コード例 #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
 private bool CheckServiceExisted(HostCollection service, string serviceProgId)
 {
     return(opcDaServices.Any(item => { return item.Host == service.Host && item.ServiceId == serviceProgId; }));
 }