示例#1
0
            public static void Main1()
            {
                // Instantiate the client object and hook events
                var easyUAClient = new EasyUAClient();

                easyUAClient.EventNotification += easyUAClient_EventNotification;

                Console.WriteLine("Subscribing...");
                easyUAClient.SubscribeEvent(
                    "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                    UAObjectIds.Server,
                    1000,
                    new UAEventFilterBuilder(
                        // Either the severity is >= 500, or the event comes from a specified source node
                        UAFilterElements.Or(
                            UAFilterElements.GreaterThanOrEqual(UABaseEventObject.Operands.Severity, 500),
                            UAFilterElements.Equals(
                                UABaseEventObject.Operands.SourceNode,
                                new UANodeId("nsu=http://opcfoundation.org/Quickstarts/AlarmCondition;ns=2;s=1:Metals/SouthMotor"))),
                        UABaseEventObject.AllFields));

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

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeAllMonitoredItems();

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);
            }
示例#2
0
            public static void Events()
            {
                // Instantiate the client object and hook events
                var easyUAClient = new EasyUAClient();

                easyUAClient.EventNotification += easyUAClient_EventNotification;

                Console.WriteLine("Subscribing...");
                easyUAClient.SubscribeMultipleMonitoredItems(new[]
                {
                    new EasyUAMonitoredItemArguments("firstState",
                                                     "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                                                     UAObjectIds.Server,
                                                     new UAMonitoringParameters(1000, new UAEventFilterBuilder(
                                                                                    UAFilterElements.GreaterThanOrEqual(UABaseEventObject.Operands.Severity, 500),
                                                                                    UABaseEventObject.AllFields)))
                    {
                        AttributeId = UAAttributeId.EventNotifier
                    },
                    new EasyUAMonitoredItemArguments("secondState",
                                                     "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                                                     UAObjectIds.Server,
                                                     new UAMonitoringParameters(2000, new UAEventFilterBuilder(
                                                                                    UAFilterElements.Equals(
                                                                                        UABaseEventObject.Operands.SourceNode,
                                                                                        new UANodeId("nsu=http://opcfoundation.org/Quickstarts/AlarmCondition;ns=2;s=1:Metals/SouthMotor")),
                                                                                    UABaseEventObject.AllFields)))
                    {
                        AttributeId = UAAttributeId.EventNotifier
                    },
                });

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

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeAllMonitoredItems();

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);
            }
示例#3
0
            public static void Main1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                UANodeId nodeId = null;

                byte[] eventId = null;
                var    anEvent = new ManualResetEvent(initialState: false);

                Console.WriteLine("Subscribing...");
                easyUAClient.SubscribeEvent(
                    "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                    UAObjectIds.Server,
                    1000,
                    new UAEventFilterBuilder(
                        UAFilterElements.Equals(
                            UABaseEventObject.Operands.NodeId,
                            new UANodeId(expandedText: "nsu=http://opcfoundation.org/Quickstarts/AlarmCondition;ns=2;s=1:Colours/EastTank?Yellow")),
                        UABaseEventObject.AllFields),
                    (sender, eventArgs) =>
                {
                    if (!eventArgs.Succeeded)
                    {
                        Console.WriteLine(eventArgs.ErrorMessageBrief);
                        return;
                    }
                    if (eventArgs.EventData != null)
                    {
                        UABaseEventObject baseEventObject = eventArgs.EventData.BaseEvent;
                        Console.WriteLine(baseEventObject);

                        // Make sure we do not catch the event more than once
                        if (anEvent.WaitOne(0))
                        {
                            return;
                        }

                        nodeId  = baseEventObject.NodeId;
                        eventId = baseEventObject.EventId;

                        anEvent.Set();
                    }
                },
                    state: null);

                Console.WriteLine("Waiting for an event for 30 seconds...");
                if (!anEvent.WaitOne(30 * 1000))
                {
                    Console.WriteLine("Event not received");
                    return;
                }

                Console.WriteLine("Acknowledging an event...");
                easyUAClient.Acknowledge(
                    "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                    nodeId,
                    eventId,
                    "Acknowledged by an automated example code");

                Console.WriteLine("Waiting for 5 seconds...");
                Thread.Sleep(5 * 1000);

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeAllMonitoredItems();

                Console.WriteLine("Waiting for 5 seconds...");
                Thread.Sleep(5 * 1000);
            }