public static void Main1()
            {
                var eventHandler = new EasyAENotificationEventHandler(easyAEClient_Notification);

                EasyAEClient.Notification += eventHandler;

                Console.WriteLine("Processing event notifications...");
                var subscriptionFilter = new AESubscriptionFilter
                {
                    Sources = new AENodeDescriptor[] { "Simulation.ConditionState1", "Simulation.ConditionState3" }
                };
                // You can also filter using event types, categories, severity, and areas.
                int handle = EasyAEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, null, subscriptionFilter);

                // Allow time for initial refresh
                Thread.Sleep(5 * 1000);

                // Set some events to active state.
                // The activation below will come from a source contained in a filter and the notification will arrive.
                EasyDaClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState1.Activate", true);
                // The activation below will come from a source that is not contained in a filter and the notification will not arrive.
                EasyDaClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState2.Activate", true);

                Thread.Sleep(10 * 1000);

                EasyAEClient.UnsubscribeEvents(handle);
            }
Example #2
0
            public static void FilterByCategories()
            {
                var eventHandler = new EasyAENotificationEventHandler(easyAEClient_Notification_FilterByCategories);

                EasyAEClient.Notification += eventHandler;

                Console.WriteLine("Processing event notifications...");
                var subscriptionFilter = new AESubscriptionFilter
                {
                    Categories = new long[] { 15531778 }
                };
                // You can also filter using event types, severity, areas, and sources.
                int handle = EasyAEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, null, subscriptionFilter);

                // Allow time for initial refresh
                Thread.Sleep(5 * 1000);

                // Set some events to active state.
                EasyDaClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState1.Activate", true);
                EasyDaClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState2.Activate", true);

                Thread.Sleep(10 * 1000);

                EasyAEClient.UnsubscribeEvents(handle);
            }
            public static void Main1()
            {
                var eventHandler = new EasyAENotificationEventHandler(easyAEClient_Notification);

                EasyAEClient.Notification += eventHandler;

                Console.WriteLine("Processing event notifications...");
                var subscriptionFilter = new AESubscriptionFilter
                {
                    Sources = new AENodeDescriptor[]
                    { "Simulation.ConditionState1", "Simulation.ConditionState2", "Simulation.ConditionState3" }
                };
                int handle = EasyAEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, null, subscriptionFilter);

                // The component will perform auto-refresh at this point, give it time to happen
                Console.WriteLine("Waiting for 10 seconds...");
                Thread.Sleep(10 * 1000);

                // Set some events to active state, which will cause them to appear in refresh
                Console.WriteLine("Activating conditions and waiting for 10 seconds...");
                EasyDaClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState1.Activate", true);
                EasyDaClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState2.Activate", true);
                Thread.Sleep(10 * 1000);

                Console.WriteLine("Refreshing subscription and waiting for 10 seconds...");
                EasyAEClient.RefreshEventSubscription(handle);
                Thread.Sleep(10 * 1000);

                EasyAEClient.UnsubscribeEvents(handle);
            }
            public static void Main1()
            {
                var eventHandler = new EasyAENotificationEventHandler(easyAEClient_Notification);

                EasyAEClient.Notification += eventHandler;

                Console.WriteLine("Processing event notifications for 1 minute...");
                var subscriptionFilter = new AESubscriptionFilter
                {
                    Sources = new AENodeDescriptor[] { "Simulation.ConditionState1" }
                };
                int handle = EasyAEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, null, subscriptionFilter);

                // Give the refresh operation time to complete
                Thread.Sleep(5 * 1000);

                // Trigger an acknowledgeable event
                EasyDAClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState1.Activate", true);

                _done = false;
                DateTime endTime = DateTime.Now + new TimeSpan(0, 0, 5);

                while ((!_done) && (DateTime.Now < endTime))
                {
                    Thread.Sleep(1000);
                }

                // Give some time to also receive the acknowledgement notification
                Thread.Sleep(5 * 1000);

                EasyAEClient.UnsubscribeEvents(handle);
            }
            public static void Main1()
            {
                var easyAEClient = new EasyAEClient();
                var easyDAClient = new EasyDAClient();

                var eventHandler = new EasyAENotificationEventHandler(easyAEClient_Notification);

                easyAEClient.Notification += eventHandler;

                // Inactivate the event condition (we will later activate it and receive the notification)
                easyDAClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState1.Inactivate", true);

                var subscriptionFilter = new AESubscriptionFilter
                {
                    Sources = new AENodeDescriptor[] { "Simulation.ConditionState1" }
                };

                // Prepare a dictionary holding requested event attributes for each event category
                // The event category IDs and event attribute IDs are hard-coded here, but can be obtained from the OPC
                // server by querying as well.
                var returnedAttributesByCategory = new AEAttributeSetDictionary();

                returnedAttributesByCategory[0x00ECFF02] = new long[] { 0x00EB0003, 0x00EB0008 };

                Console.WriteLine("Subscribing to events...");
                int handle = easyAEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, null, subscriptionFilter,
                                                          returnedAttributesByCategory);

                // Give the refresh operation time to complete
                Thread.Sleep(5 * 1000);

                // Trigger an event carrying specified attributes (activate the condition)
                easyDAClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1",
                                            "SimulateEvents.ConditionState1.AttributeValues.15400963", 123456);
                easyDAClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1",
                                            "SimulateEvents.ConditionState1.AttributeValues.15400968", "Some string value");
                easyDAClient.WriteItemValue("", "AutoJet.ACPFileServerAE.1", "SimulateEvents.ConditionState1.Activate", true);

                Console.WriteLine("Processing event notifications for 10 seconds...");
                Thread.Sleep(10 * 1000);

                easyAEClient.UnsubscribeEvents(handle);
            }