Example #1
0
        private void Subscribe(string nodeId, string motorType)
        {
            referenceDescriptionCollection = myClientHelperAPI.ReadStructProperties(nodeId);
            Subscription subscription = myClientHelperAPI.Subscribe(1000);

            mySubscriptions.Add(subscription);

            try
            {
                foreach (ReferenceDescription tempRefDesc in referenceDescriptionCollection)
                {
                    //use different item names for correct assignment at the notificatino event
                    if (tempRefDesc.DisplayName.ToString().Contains("startAnyway"))
                    {
                        if (motorType == "cooling")
                        {
                            coolingStartAnywayNodeId = tempRefDesc.NodeId.ToString();
                        }
                        else if (motorType == "heating")
                        {
                            heatingStartAnywayNodeId = tempRefDesc.NodeId.ToString();
                        }
                    }

                    if (tempRefDesc.DisplayName.ToString().Contains("speed"))
                    {
                        if (motorType == "cooling")
                        {
                            coolingSpeedNodeId = tempRefDesc.NodeId.ToString();
                        }
                        else if (motorType == "heating")
                        {
                            heatingSpeedNodeId = tempRefDesc.NodeId.ToString();
                        }
                    }

                    string monitoredItemName = motorType + "-" + tempRefDesc.DisplayName.ToString();
                    myMonitoredItem = myClientHelperAPI.AddMonitoredItem(mySubscriptions[mySubscriptions.Count() - 1], tempRefDesc.NodeId.ToString(), monitoredItemName, 1);
                    myClientHelperAPI.ItemChangedNotification = new MonitoredItemNotificationEventHandler(Notification_MonitoredItem);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Example #2
0
        /// <summary>
        /// Starts the monitoring of the values of the two variables entered in the From.
        /// The NodeIds used for the monitoring are constructed from the identifier entered
        /// in the Form and the namespace index detected in the connect method
        /// </summary>
        private void btnMonitor_Click(object sender, EventArgs e)
        {
            // Check if we have a subscription
            //  - No  -> Create a new subscription and create monitored items
            //  - Yes -> Delete Subcription
            if (m_Subscription == null)
            {
                try
                {
                    // Create subscription
                    m_Subscription = m_Server.Subscribe(1000);
                    m_Server.ItemChangedNotification += new MonitoredItemNotificationEventHandler(ClientApi_ValueChanged);
                    btnMonitor.Text = "Stop";

                    // Create first monitored item
                    m_Server.AddMonitoredItem(m_Subscription, new NodeId(txtIdentifier1.Text, m_NameSpaceIndex).ToString(), "item1", 100);


                    // Create second monitored item
                    m_Server.AddMonitoredItem(m_Subscription, new NodeId(txtIdentifier2.Text, m_NameSpaceIndex).ToString(), "item2", 100);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Establishing data monitoring failed:\n\n" + ex.Message);
                }
            }
            else
            {
                try
                {
                    m_Server.RemoveSubscription(m_Subscription);
                    m_Subscription = null;

                    btnMonitor.Text    = "Monitor";
                    txtMonitored1.Text = "";
                    txtMonitored2.Text = "";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Stopping data monitoring failed:\n\n" + ex.Message);
                }
            }
        }
Example #3
0
        /// <summary>
        /// 添加订阅
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public bool AddSubscription(TagItem tag)
        {
            MonitoredItem item = uAClient.AddMonitoredItem(_Subscription, tag.GetNodeId(), tag.Name, tag.SampleRate);

            _SubscriptionTags.Add(tag.ServerId, tag);
            _MonitorItem.Add(tag.ServerId, item);
            if (item.Created)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Finishes a drag and drop action whereas this control is used as target.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void MonitoredItems_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                // Retrieve the event data and create the according nodeid.
                String sNodeId = (String)e.Data.GetData(typeof(System.String));

                // Create the subscription if it does not already exist.
                if (m_Subscription == null)
                {
                    m_Subscription = m_Server.Subscribe(200);
                    m_Server.ItemChangedNotification += new MonitoredItemNotificationEventHandler(ClientApi_ValueChanged);
                }

                // Add the attribute name/value to the list view.
                ListViewItem item         = new ListViewItem(sNodeId);
                object       serverHandle = null;

                // Prepare further columns.
                item.SubItems.Add("100"); // Sampling interval by default.
                item.SubItems.Add(String.Empty);
                item.SubItems.Add(String.Empty);
                item.SubItems.Add(String.Empty);
                item.SubItems.Add(String.Empty);
                item.SubItems.Add(String.Empty);

                try
                {
                    // Add the item and apply any changes to it.
                    MonitoredItem tempMonitoredItem = m_Server.AddMonitoredItem(m_Subscription, sNodeId, "item1", 100);
                    tempMonitoredItem.Handle = item;
                    serverHandle             = tempMonitoredItem;

                    // Update status label.
                    OnUpdateStatusLabel("Adding monitored item succeeded for NodeId:" +
                                        sNodeId, true);
                }
                catch (ServiceResultException monitoredItemResult)
                {
                    item.SubItems[5].Text = monitoredItemResult.StatusCode.ToString();

                    // Update status label.
                    OnUpdateStatusLabel("An exception occured while adding an item: " +
                                        monitoredItemResult.Message, false);
                }

                item.Tag = serverHandle;
                MonitoredItemsLV.Items.Add(item);

                // Fit column width to the longest item and add a few pixel:
                MonitoredItemsLV.Columns[0].Width  = -1;
                MonitoredItemsLV.Columns[0].Width += 15;
                // Fit column width to the column content:
                MonitoredItemsLV.Columns[1].Width = -2;
                MonitoredItemsLV.Columns[5].Width = -2;
                // Fix settings:
                MonitoredItemsLV.Columns[2].Width = 95;
                MonitoredItemsLV.Columns[3].Width = 75;
                MonitoredItemsLV.Columns[4].Width = 75;
            }
            catch (Exception exception)
            {
                // Update status label.
                OnUpdateStatusLabel("An exception occured while creating a subscription: " +
                                    exception.Message, false);
            }
        }