Пример #1
0
        public void MonitorDataChange(RemoteDataMonitor monitor, RemoteObject remoteObject)
        {
            var monitoredItems = new List <MonitoredItem>
            {
                new DataMonitoredItem(BrowseNodeId(_parentNode, monitor.Name))
                {
                    UserData          = monitor,
                    DataChangeTrigger = DataChangeTrigger.StatusValue
                }
            };

            remoteObject.SessionHandle.ClientSubscription().CreateMonitoredItems(monitoredItems,
                                                                                 new RequestSettings {
                OperationTimeout = 10000
            });

            remoteObject.SessionHandle.SetDataChangeHandler(
                (ss, args) =>
            {
                Logger.Info("Received DATA CHANGE ...");
                foreach (var dataChange in args.DataChanges)
                {
                    var remoteDataMonitor = (RemoteDataMonitor)dataChange.MonitoredItem.UserData;
                    remoteDataMonitor?.DataChange(dataChange.Value.WrappedValue);
                }
            });

            remoteObject.SessionHandle.MonitoredItems.AddRange(monitoredItems);
        }
Пример #2
0
        public void Monitor(string name, Action <Variant> action)
        {
            try
            {
                var monitor = new RemoteDataMonitor
                {
                    Name     = name,
                    Value    = Variant.Null,
                    Callback = action
                };

                monitor.Announce(this);
            }
            catch (Exception e)
            {
                ExceptionHandler.Log(e, $"Cannot subscribe MONITORED ITEM '{Name}.{name}'.");
            }
        }