Ejemplo n.º 1
0
        //-----------------

        public MyAeSubscription(MyAeSession parentSession) : base(parentSession)
        {
            PerformStateTransitionCompleted += new PerformStateTransitionEventHandler(HandlePerformObjectStateTransitionCompleted);
            StateChangeCompleted            += new StateChangeEventHandler(HandleStateChangeCompleted);
            AeEventsReceived    += new AeEventsReceivedEventHandler(HandleEventsReceived);
            AeConditionsChanged += new AeConditionsChangedEventHandler(HandleConditionsChanged);
        }
Ejemplo n.º 2
0
        }           //    end ProcessCommandLine

        public void Terminate()
        {
            // disconnect all the connected objects
            if (m_aeSubscription.CurrentState != EnumObjectState.DISCONNECTED)
            {
                m_aeSubscription.Disconnect(new ExecutionOptions());
            }

            if (m_aeSession.CurrentState != EnumObjectState.DISCONNECTED)
            {
                m_aeSession.Disconnect(new ExecutionOptions());
            }

            // remove subscription from session
            m_aeSession.RemoveAeSubscription(m_aeSubscription);

            // remove session from application
            GetApplication().RemoveAeSession(m_aeSession);

            // terminate the application
            GetApplication().Terminate();
            m_aeSession        = null;
            m_aeSubscription   = null;
            m_executionOptions = null;
        }           //    end Terminate
Ejemplo n.º 3
0
        }        //end GetConditionState

        public int InitializeAeObjects()
        {
            int connectResult = (int)EnumResultCode.E_FAIL;

            m_executionOptions = new ExecutionOptions();
            m_executionOptions.ExecutionType    = EnumExecutionType.ASYNCHRONOUS;
            m_executionOptions.ExecutionContext = 0;

            try
            {
                m_aeSession      = new MyAeSession("opcae:///Softing.OPCToolboxDemo_ServerAE.1/{2E565243-B238-11D3-842D-0008C779D775}");
                m_aeSubscription = new MyAeSubscription(m_aeSession);

                connectResult = m_aeSession.Connect(true, false, new ExecutionOptions());

                //define the event areas that will be used to filter events
                //TODO replace the array below with your own areas
                // NOTE: Areas excluded from this filter will not send events/conditions to the AE client.
                //       If no filter is set, all areas will fire events.
                string[] areas = new string[] { "computer.mouse", "computer.clock" };

                //set the previously defined areas for filtering
                m_aeSubscription.FilterAreas = areas;

                //define the event sources that will be used to filter events
                //TODO replace the array below with your own sources
                // NOTE: Sources excluded from this filter will not send events/conditions to the AE client.
                //       If no filter is set, all sources will fire events.
                string[] sources = new string[] { "computer.mouse.right button", "computer.mouse.middle button", "computer.clock.timer", "computer.clock.time slot 1", "computer.clock.time slot 2" };

                //set the previously defined sources for filtering
                m_aeSubscription.FilterSources = sources;

                //define the categories that will be used to filter events ("time tick" category is used)
                //TODO replace the array below with your own category ids
                // NOTE: Category IDs excluded from this filter will not send events/conditions to the AE client.
                //       If no filter is set, all categories will fire events.
                uint[] categoryIds = new uint[] { 1, 2, 3 };

                //set the previously defines categoryIds for filtering
                m_aeSubscription.FilterCategories = categoryIds;

                // NOTE: Event/conditions property IDs not included in this filter will not be displayed.
                //       If no property filter is set, NO PROPERTIES WILL BE SENT WITH EACH EVENT/CONDITION (except for standard AE event/condition properties).
                AeReturnedAttributes[] returnedAttributes = new AeReturnedAttributes[3];

                // category ID: 1 (time tick)
                // attribute IDs: 1 (second)
                uint[] attributeIds = new uint[1];
                attributeIds[0]       = 1;
                returnedAttributes[0] = new AeReturnedAttributes();
                returnedAttributes[0].AttributeIds = attributeIds;
                returnedAttributes[0].CategoryId   = 1;

                // category ID: 2 (time slot)
                // attribute IDs: 2 (second), 3 (start second), 4 (end second)
                attributeIds          = new uint[3];
                attributeIds[0]       = 2;
                attributeIds[1]       = 3;
                attributeIds[2]       = 4;
                returnedAttributes[1] = new AeReturnedAttributes();
                returnedAttributes[1].AttributeIds = attributeIds;
                returnedAttributes[1].CategoryId   = 2;

                // category ID: 3 (mouse click)
                // attribute IDs: 5 (x position), 6 (y position)
                attributeIds          = new uint[2];
                attributeIds[0]       = 5;
                attributeIds[1]       = 6;
                returnedAttributes[2] = new AeReturnedAttributes();
                returnedAttributes[2].AttributeIds = attributeIds;
                returnedAttributes[2].CategoryId   = 3;

                m_aeSubscription.ReturnedAttributes = returnedAttributes;
            }
            catch (Exception exc)
            {
                GetApplication().Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.USER,
                    "OpcClient::InitializeAeObjects",
                    exc.ToString());
            }               //    end try...catch

            return(connectResult);
        }           //    end InitializeAeObjects