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); }
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 UAAttributeFieldCollection { // Select specific fields using standard operand symbols UABaseEventObject.Operands.NodeId, UABaseEventObject.Operands.SourceNode, UABaseEventObject.Operands.SourceName, UABaseEventObject.Operands.Time, // Select specific fields using an event type ID and a simple relative path UAFilterElements.SimpleAttribute(UAObjectTypeIds.BaseEventType, "/Message"), UAFilterElements.SimpleAttribute(UAObjectTypeIds.BaseEventType, "/Severity"), }); 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); }
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); }
static void easyUAClient_EventNotification(object sender, EasyUAEventNotificationEventArgs e) { Console.WriteLine(); // Display the event if (e.EventData == null) { Console.WriteLine(e); return; } Console.WriteLine("All fields:"); foreach (KeyValuePair <UAAttributeField, ValueResult> pair in e.EventData.FieldResults) { UAAttributeField attributeField = pair.Key; ValueResult valueResult = pair.Value; Console.WriteLine(" {0} -> {1}", attributeField, valueResult); } // Extracting a specific field using a standard operand symbol Console.WriteLine("Source name: {0}", e.EventData.FieldResults[UABaseEventObject.Operands.SourceName]); // Extracting a specific field using an event type ID and a simple relative path Console.WriteLine("Message: {0}", e.EventData.FieldResults[UAFilterElements.SimpleAttribute(UAObjectTypeIds.BaseEventType, "/Message")]); }
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); }