コード例 #1
0
        public async Task CreateSessionAsync(OpcUaClientConfiguration config)
        {
            SysLog.Info("Creating the Opcua client session.");
            try
            {
                var endpoint = config.Endpoint;
                if (endpoint != null)
                {
                    var appConfig = await config.LoadOpcUaConfiguration();

                    appConfig.SecurityConfiguration.AutoAcceptUntrustedCertificates = true;
                    appConfig.CertificateValidator.CertificateValidation           += (validator, e) => e.Accept = true;
                    if (endpoint.Description.SecurityPolicyUri != SecurityPolicies.None)
                    {
                        await appConfig.SecurityConfiguration.ApplicationCertificate?.Find(true);
                    }

                    var identity = GetUserIdentity(endpoint);
                    _session = await Session.Create(appConfig, endpoint, true, false, Constants.DefaultSessionName, Constants.DefaultSessionTimeoutMs, identity, null);

                    SysLog.Info("OpcUa client session successfully created");
                }
                else
                {
                    SysLog.Warn("Failed to get OPC server url from connector source config.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to load application configuration.", ex);
            }
        }
コード例 #2
0
        public OpcUaClient(AppSettings appSettings, Action <MonitoredItem, MonitoredItemNotificationEventArgs> callback)
        {
            _appSettings = appSettings;
            _callback    = callback;
            _currentListMonitoredItemsSubscribed = new List <MonitoredItem>();
            _config = new OpcUaClientConfiguration(appSettings.OpcUaServerUrl);
            _checkConnectionTimer = new Timer
            {
                Interval = TimeSpan.FromMilliseconds(this._appSettings.ConnectionCheckIntervalMs).TotalMilliseconds
            };

            CreateOpcuaSessionAsync().GetAwaiter().GetResult();

            CreateSubscription();
        }