Beispiel #1
0
        //public bool IsConnectedToOPCDAServer { get { if (oPCDAServer == null) return false; else return oPCDAServer.IsConnected; } }
        #endregion


        public OPCClassicBrowserEngine()
        {
            this.OPCGroupSizeLimit = OPCBackEnd.Config.OPCClassic_SubscriptionGroupSizeLimit.ToInt(40);
            _OPCWrapper            = new OpcCom.ServerEnumerator();
            _BrowseFilters         = new Opc.Da.BrowseFilters()
            {
                ReturnAllProperties  = true,
                ReturnPropertyValues = true,
                BrowseFilter         = Opc.Da.browseFilter.all,
                MaxElementsReturned  = 0
            };


            //Check for Tag Inactivity every 5s. Every call by client will update it's activity.
            //If tag has been inactive for more than 3x it's update interval, remove the tag from subscription (5s min inactivity time)
            OPTimer CheckInactivityTimer = new OPTimer("OPC Classic Browser Engine Check Inactivity Timer", 5000);

            CheckInactivityTimer.Elapsed += (s) =>
            {
                List <RegisteredTag> InactiveTags = this.RegisteredTags.Values.Where(RT =>
                {
                    if (RT.UpdateIntervalInMS <= 5000)
                    {
                        return((DateTime.Now - RT.LastCalled).TotalMilliseconds > 5000);
                    }
                    else
                    {
                        return((DateTime.Now - RT.LastCalled).TotalMilliseconds > 3 * RT.UpdateIntervalInMS);
                    }
                }).ToList();
                foreach (RegisteredTag InactiveTag in InactiveTags)
                {
                    foreach (Opc.Da.Server OPCServer in _OPCDAServers)
                    {
                        if (!OPCServer.IsConnected)
                        {
                            continue;
                        }
                        Subscription SubscriptionWhereInactiveTagIs = OPCServer.Subscriptions.FindSubcriptionThatHasItem(InactiveTag.Id, out Item InactiveItem);
                        if (SubscriptionWhereInactiveTagIs != null)
                        {
                            SubscriptionWhereInactiveTagIs.RemoveItems(new ItemIdentifier[] { InactiveItem });
                        }
                    }
                    this.RegisteredTags.Remove(InactiveTag.Id);
                }
                return(Task.CompletedTask);
            };
            CheckInactivityTimer.Start();
        }
Beispiel #2
0
        public OPCUABrowserEngine(string SSLCertificateDirectory = null)
        {
            this.OPCGroupSizeLimit = OPCBackEnd.Config.OPCCUA_SubscriptionGroupSizeLimit.ToInt(40);
            #region GENERATE APPLICATION CONFIGURATION
            _OPCWrapper = new OpcCom.ServerEnumerator();
            if (SSLCertificateDirectory == null)
            {
                _SSLCertificateDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Vlix\\VlixOPC\\Certs";
            }
            else
            {
                _SSLCertificateDirectory = SSLCertificateDirectory;
            }
            _Config = new ApplicationConfiguration()
            {
                ApplicationName       = "VlixOPCUABrowser",
                ApplicationType       = ApplicationType.Client,
                SecurityConfiguration = new SecurityConfiguration
                {
                    //This is the App's certificate that should exist it the 'Own' directory
                    ApplicationCertificate = new CertificateIdentifier
                    {
                        StoreType   = @"Directory",
                        StorePath   = _SSLCertificateDirectory + "\\Own",
                        SubjectName = Utils.Format(@"CN={0}, DC={1}", "VlixOPCUABrowser", System.Net.Dns.GetHostName())
                    },
                    TrustedPeerCertificates = new CertificateTrustList {
                        StoreType = @"Directory", StorePath = _SSLCertificateDirectory + "\\Trusted",
                    },
                    TrustedIssuerCertificates = new CertificateTrustList {
                        StoreType = @"Directory", StorePath = _SSLCertificateDirectory + "\\Issuers",
                    },
                    RejectedCertificateStore = new CertificateTrustList {
                        StoreType = @"Directory", StorePath = _SSLCertificateDirectory + "\\Rejected",
                    },
                    NonceLength = 32,
                    AutoAcceptUntrustedCertificates = true
                },
                TransportConfigurations = new TransportConfigurationCollection(),
                TransportQuotas         = new TransportQuotas {
                    OperationTimeout = 15000
                },
                ClientConfiguration = new ClientConfiguration {
                    DefaultSessionTimeout = 60000
                },
                DisableHiResClock = true
            };
            _Config.Validate(ApplicationType.Client); //This only checks if any certificates exists (in the predefined area). If no certificates exist, nothing will happen.
            #endregion


            OPTimer CheckInactivityTimer = new OPTimer("OPCUABrowserEngine Check Inactivity Timer", 5000);
            CheckInactivityTimer.Elapsed += (s) =>
            {
                List <RegisteredTag> InactiveTags = this.RegisteredTags.Values.Where(RT =>
                {
                    if (RT.UpdateIntervalInMS <= 5000)
                    {
                        return((DateTime.Now - RT.LastCalled).TotalMilliseconds > 5000);
                    }
                    else
                    {
                        return((DateTime.Now - RT.LastCalled).TotalMilliseconds > 3 * RT.UpdateIntervalInMS);
                    }
                }).ToList();
                foreach (RegisteredTag InactiveTag in InactiveTags)
                {
                    foreach (OPCUAServer OPCServer in _OPCUAServers)
                    {
                        if (OPCServer.Session == null || !OPCServer.Session.Connected)
                        {
                            continue;
                        }
                        //ILocalNode NodeIdObject = OPCServer.Session.NodeCache.Find(new NodeId(InactiveTag.Id)) as ILocalNode;
                        Subscription SubscriptionWhereInactiveTagIs = OPCServer.Session.Subscriptions.FindSubcriptionThatHasItem(InactiveTag.Id, out MonitoredItem InactiveItem);
                        if (SubscriptionWhereInactiveTagIs != null)
                        {
                            SubscriptionWhereInactiveTagIs.RemoveItem(InactiveItem);
                        }
                    }
                    this.RegisteredTags.Remove(InactiveTag.Id);
                }
            };
            CheckInactivityTimer.Start();
        }