Exemple #1
0
        public int InitializeAeObjects(string url)
        {
            int connectResult = (int)EnumResultCode.E_FAIL;

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

            try
            {
                m_aeSession      = new MyAeSession(url);
                m_aeSubscription = new MyAeSubscription(m_aeSession);

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

                uint[] categoryIds = new uint[]
                {
                    (uint)CategoriesAndAttribute.Categories.System_alarm,
                    (uint)CategoriesAndAttribute.Categories.Process_alarm,
                    (uint)CategoriesAndAttribute.Categories.Operation_record
                };
                m_aeSubscription.FilterCategories = categoryIds;

                AeReturnedAttributes[] returnedAttributes = new AeReturnedAttributes[categoryIds.Length];
                for (int i = 0; i < categoryIds.Length; i++)
                {
                    List <uint> temp         = CategoriesAndAttribute.getAttributeIDsFromCategoryID(categoryIds[i]);
                    uint[]      attributeIds = new uint[temp.Count];
                    attributeIds          = temp.ToArray();
                    returnedAttributes[i] = new AeReturnedAttributes();
                    returnedAttributes[i].AttributeIds = attributeIds;
                    returnedAttributes[i].CategoryId   = categoryIds[i];
                }
                m_aeSubscription.ReturnedAttributes = returnedAttributes;
            }
            catch (Exception exc)
            {
                GetApplication().Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.USER,
                    "OpcClient::InitializeAeObjects",
                    exc.ToString());
            }   //    end try...catch

            return(connectResult);
        }       //    end InitializeAeObjects
Exemple #2
0
        }        // end CheckSubscription

        public int ChangeSubscriptionAttributes()
        {
            int[] updateResults = new int[1];
            int   operationResult;

            AeReturnedAttributes attrs1 = new AeReturnedAttributes();

            attrs1.CategoryId   = 2;
            attrs1.AttributeIds = new uint[] { 3, 4 };
            AeReturnedAttributes attrs2 = new AeReturnedAttributes();

            attrs2.CategoryId   = 3;
            attrs2.AttributeIds = new uint[] { 6 };
            m_aeSubscription.ReturnedAttributes = new AeReturnedAttributes[] { attrs1, attrs2 };

            // write changed data to the server
            operationResult = m_aeSubscription.SetAttributesToServer(
                new EnumObjectAttribute[] { EnumObjectAttribute.AESUBSCRIPTION_RETURNED_ATTRIBUTES },
                out updateResults,
                new ExecutionOptions());

            return(operationResult);
        }        // end ChangeSubscriptionAttributes
        }        //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