Exemple #1
0
        private void subscribeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((NodeId)BrowseCTRL.SelectedNode.NodeId != null)
            {
                if (subscriptionOutputWindow == null)
                {
                    subscriptionOutputWindow = new SubscriptionOutput();
                }

                if (m_subscription == null)
                {
                    m_subscription = new Subscription(m_session.DefaultSubscription);
                    m_subscription.PublishingEnabled  = true;
                    m_subscription.PublishingInterval = 1000;
                    m_session.AddSubscription(m_subscription);
                    m_subscription.Create();
                }

                if (monitoredItems.Count == 0)
                {
                    if (BrowseCTRL.GetChildOfSelectedNode(0) != null)
                    {
                        BrowseDescription nodeToBrowse = new BrowseDescription();
                        nodeToBrowse.NodeId = (NodeId)BrowseCTRL.SelectedNode.NodeId;

                        nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
                        nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences;
                        nodeToBrowse.IncludeSubtypes = true;
                        //nodeToBrowse.NodeClassMask = (uint)(NodeClass.Object);
                        nodeToBrowse.ResultMask = (uint)(BrowseResultMask.All);

                        ReferenceDescriptionCollection references = ClientUtils.Browse(m_session, nodeToBrowse, false);
                        subscriptionOutputWindow.label1.Text = "You selected a folder: these are the child nodes:\n";
                        foreach (var item in references)
                        {
                            var mi = new MonitoredItem(m_subscription.DefaultItem);
                            mi.StartNodeId      = (NodeId)item.NodeId;
                            mi.AttributeId      = Attributes.DisplayName;
                            mi.MonitoringMode   = MonitoringMode.Reporting;
                            mi.SamplingInterval = 1000;
                            mi.QueueSize        = 0;
                            mi.DiscardOldest    = true;
                            mi.Notification    += new MonitoredItemNotificationEventHandler(Mi_Notification);
                            monitoredItems.Add(mi);
                        }
                    }
                    else
                    {
                        var mi = new MonitoredItem(m_subscription.DefaultItem);
                        mi.StartNodeId      = (NodeId)BrowseCTRL.SelectedNode.NodeId;
                        mi.AttributeId      = Attributes.Value;
                        mi.MonitoringMode   = MonitoringMode.Reporting;
                        mi.SamplingInterval = 1000;
                        mi.QueueSize        = 0;
                        mi.DiscardOldest    = true;
                        mi.Notification    += new MonitoredItemNotificationEventHandler(Mi_Notification);
                        // define event handler for this item, and then add to subscription
                        mi.Notification += new MonitoredItemNotificationEventHandler(monitoredItem_Notification);
                        monitoredItems.Add(mi);
                    }
                    m_subscription.AddItems(monitoredItems);
                }
                subscriptionOutputWindow.Show();
                subscriptionOutputWindow.FormClosed += OutputWindow_FormClosed;
                m_subscription.ApplyChanges();
            }
        }
 /// <summary>
 /// Returns the child node at the specified index.
 /// </summary>
 public ReferenceDescription GetChildOfSelectedNode(int index)
 {
     return(BrowseCTRL.GetChildOfSelectedNode(index));
 }