Exemple #1
0
 /// <summary>
 /// 断开连接
 /// </summary>
 /// <returns></returns>
 public bool Disconnect()
 {
     RemoveSubscription();
     uAClient.RemoveSubscription(_Subscription);
     uAClient.Disconnect();
     return(true);
 }
Exemple #2
0
        private void Notification_KeepAlive(Session sender, KeepAliveEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new KeepAliveEventHandler(Notification_KeepAlive), sender, e);
                return;
            }

            // check for events from discarded sessions.
            if (!Object.ReferenceEquals(sender, mySession))
            {
                return;
            }

            // check for disconnected session.
            if (!ServiceResult.IsGood(e.Status))
            {
                //                UpdateLog("Client", "Lost connection to server; Reconnect failed", false);

                //Release connection
                try
                {
                    myHelperApi.RemoveSubscription(mySubscription);
                }
                catch
                {
                    ;
                }
                myHelperApi.Disconnect();
                mySession = myHelperApi.Session;
                //               ClearUI();
            }
        }
 public void RemoveSubscription()
 {
     if (m_Subscription != null)
     {
         m_Server.RemoveSubscription(m_Subscription);
         m_Subscription = null;
     }
 }
Exemple #4
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);
                }
            }
        }