Пример #1
0
        /// <summary>
        /// Called when the close button is clicked.
        /// </summary>
        private void DoneBTN_Click(object sender, System.EventArgs e)
        {
            try
            {
                m_areas   = AreaSourcesListCTRL.GetAreas();
                m_sources = AreaSourcesListCTRL.GetSources();

                // don't activate until all the filters are applied.
                bool active = m_state.Active;
                bool update = m_subscription != null;

                // create new subscription.
                if (m_subscription == null)
                {
                    m_state.Active       = false;
                    m_state.ClientHandle = Guid.NewGuid().ToString();
                    m_subscription       = (Ae.TsCAeSubscription)m_server.CreateSubscription(m_state);
                }

                // update existing subscription.
                else
                {
                    m_subscription.ModifyState(((int)TsCAeStateMask.All & ~(int)TsCAeStateMask.Active), m_state);
                }

                // select filters.
                m_filters.Areas.Clear();
                m_filters.Areas.AddRange(m_areas);
                m_filters.Sources.Clear();
                m_filters.Sources.AddRange(m_sources);

                m_subscription.SetFilters(m_filters);

                // select attributes.
                IDictionaryEnumerator enumerator = m_attributes.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    int categoryID = (int)enumerator.Key;
                    OpcClientSdk.Ae.TsCAeAttributeCollection attributeIDs = (OpcClientSdk.Ae.TsCAeAttributeCollection)enumerator.Value;

                    m_subscription.SelectReturnedAttributes(categoryID, attributeIDs.ToArray());
                }

                // activate the subscription.
                if (active || update)
                {
                    m_state.Active = active;
                    m_subscription.ModifyState((int)TsCAeStateMask.Active, m_state);
                }

                // close the dialog.
                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Called when the close button is clicked.
        /// </summary>
        private void DoneBTN_Click(object sender, System.EventArgs e)
        {
            try
            {
                mAreas_   = areaSourcesListCtrl_.GetAreas();
                mSources_ = areaSourcesListCtrl_.GetSources();

                // don't activate until all the filters are applied.
                bool active = mState_.Active;
                bool update = mSubscription_ != null;

                // create new subscription.
                if (mSubscription_ == null)
                {
                    mState_.Active       = false;
                    mState_.ClientHandle = Guid.NewGuid().ToString();
                    mSubscription_       = (TsCAeSubscription)mServer_.CreateSubscription(mState_);
                }

                // update existing subscription.
                else
                {
                    mSubscription_.ModifyState(((int)TsCAeStateMask.All & ~(int)TsCAeStateMask.Active), mState_);
                }

                // select filters.
                mFilters_.Areas.Clear();
                mFilters_.Areas.AddRange(mAreas_);
                mFilters_.Sources.Clear();
                mFilters_.Sources.AddRange(mSources_);

                mSubscription_.SetFilters(mFilters_);

                // select attributes.
                IDictionaryEnumerator enumerator = mAttributes_.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    int categoryId = (int)enumerator.Key;
                    Technosoftware.DaAeHdaClient.Ae.TsCAeAttributeCollection attributeIDs = (Technosoftware.DaAeHdaClient.Ae.TsCAeAttributeCollection)enumerator.Value;

                    mSubscription_.SelectReturnedAttributes(categoryId, attributeIDs.ToArray());
                }

                // activate the subscription.
                if (active || update)
                {
                    mState_.Active = active;
                    mSubscription_.ModifyState((int)TsCAeStateMask.Active, mState_);
                }

                // close the dialog.
                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        public void Run()
        {
            try
            {
                const string serverUrl = "opcae://localhost/Technosoftware.AeSample";

                Console.WriteLine();
                Console.WriteLine("Simple OPC AE Client based on the OPC AE Client SDK .NET Standard");
                Console.WriteLine("-----------------------------------------------------------------");
                Console.Write("   Press <Enter> to connect to "); Console.WriteLine(serverUrl);
                Console.ReadLine();
                Console.WriteLine("   Please wait...");

                TsCAeServer myAeServer = new TsCAeServer();

                // Connect to the server
                myAeServer.Connect(serverUrl);

                Console.WriteLine("   Connected, press <Enter> to create an active subscription and press <Enter>");
                Console.WriteLine("   again to deactivate the subscription. This stops the reception of new events.");
                Console.ReadLine();

                TsCAeSubscriptionState state = new TsCAeSubscriptionState {
                    Active = true, BufferTime = 0, MaxSize = 0, ClientHandle = 100, Name = "Simple Event Subscription"
                };

                TsCAeCategory[]  categories = myAeServer.QueryEventCategories((int)TsCAeEventType.Condition);
                TsCAeAttribute[] attributes = null;
                attributes = myAeServer.QueryEventAttributes(categories[0].ID);

                int[] attributeIDs = new int[2];

                attributeIDs[0] = attributes[0].ID;
                attributeIDs[1] = attributes[1].ID;

                TsCAeSubscription subscription;
                subscription = (TsCAeSubscription)myAeServer.CreateSubscription(state);
                subscription.DataChangedEvent += OnDataChangedEvent;
                subscription.SelectReturnedAttributes(categories[0].ID, attributeIDs);
                Console.ReadLine();

                subscription.DataChangedEvent -= OnDataChangedEvent;
                Console.WriteLine("   Subscription deactivated, press <Enter> to remove the subscription and disconnect from the server.");

                subscription.Dispose();                                                                 // Remove subscription
                myAeServer.Disconnect();                                                                // Disconnect from server
                myAeServer.Dispose();                                                                   // Dispose server object

                Console.ReadLine();
                Console.WriteLine("   Disconnected from the server.");
                Console.WriteLine();
            }
            catch (OpcResultException e)
            {
                Console.WriteLine(String.Format("   {0}", e.Message));
                Console.ReadLine();
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("   {0}", e.Message));
                Console.ReadLine();
                return;
            }
        }