Exemplo n.º 1
0
        private async Task CreateOpcuaSessionAsync()
        {
            try
            {
                if (_sessionClient == null)
                {
                    _sessionClient = new OpcUaClientSession();
                }

                await _sessionClient.CreateSessionAsync(_config);

                _monitoredItemsHandler = new MonitoredItemsHandler(_sessionClient, _appSettings);

                StartConnectionCheckTimer();

                SysLog.Info($"Connected to server: { _config.Endpoint.EndpointUrl} .");
            }
            catch (Exception)
            {
                var message = "Failed to connect to server, Please check opcua server is running";

                SysLog.Error(message);
                OnCheckConnectionTimerOnElapsed(this, new EventArgs() as ElapsedEventArgs);
                //throw new Exception(message);
            }
        }
Exemplo n.º 2
0
        public Subscription CreateSubscription(OpcUaClientSession session)
        {
            SysLog.Info("Creating new subscription ...");

            if (!session.IsConnected)
            {
                SysLog.Error("Could not create subscription because opcua client session is null. Please check the OPCUA Server status");
                return(null);
            }

            IsSubscriptionTypePublishing = true;

            _subscription = new Subscription
            {
                DisplayName                = Constants.DefaultSubscriptionName,
                PublishingInterval         = _appSettings.SubscriptionPublishIntervalMs,
                TimestampsToReturn         = TimestampsToReturn.Both,
                Priority                   = 0, //byte data type range from 0 to 255,
                KeepAliveCount             = _appSettings.SubscriptionKeepAliveCount,
                LifetimeCount              = _appSettings.SubscriptionLifetimeCount,
                MaxNotificationsPerPublish = 100000
            };

            session.AddSubscription(_subscription);

            _subscription.Create();
            _subscription.SetPublishingMode(IsSubscriptionTypePublishing);

            if (IsSubscriptionTypePublishing)
            {
                _subscription.PublishStatusChanged += OnPublishStatusChanged;
            }
            else
            {
                SysLog.Info(GetDisplayString(_subscription));
            }


            SysLog.Info("Created new subscription.");
            return(_subscription);
        }
Exemplo n.º 3
0
 public MonitoredItemsHandler(OpcUaClientSession session, AppSettings appSettings)
 {
     _session            = session;
     _appSettings        = appSettings;
     _notLocatedFileName = _appSettings.PrefixNoLocatedSensorsFileName + $"{DateTime.Now:yyyy_MM_dd_HH_mm_ss}" + ".csv";
 }