Online Forums
Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.
Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.
Do not use the Contact page for technical issues.
- Forum
- Discussions
- QuickOPC-Classic in .NET
- OPC Alarms&Events
- obtaining tag value when alarm is fired, and AttributeValues property
obtaining tag value when alarm is fired, and AttributeValues property
below is an example you asked for. I have found some problems related to event attributes during the development of this example, so you should download the recent build (5.12.1312.1 or later) from our Web site in order to make it work.
Reading DA items from inside A&E notification handler is supported in general. But you should consider any time-consuming operations inside the notifications handlers.
// This example shows how to subscribe to events with specified event attributes, and obtain the attribute values in event
// notifications.
using System;
using System.Collections.Generic;
using System.Threading;
using OpcLabs.EasyOpc.AlarmsAndEvents;
using OpcLabs.EasyOpc.DataAccess;
namespace DocExamples
{
namespace _EasyAENotificationEventArgs
{
class AttributeValues
{
public static void Main()
{
var easyAEClient = new EasyAEClient();
var easyDAClient = new EasyDAClient();
var eventHandler = new EventHandler<EasyAENotificationEventArgs>(easyAEClient_Notification);
easyAEClient.Notification += eventHandler;
// Inactivate the event condition (we will later activate it and receive the notification)
easyDAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Inactivate", true);
AESubscriptionFilter subscriptionFilter = easyAEClient.CreateSubscriptionFilter();
subscriptionFilter.Sources = new[] { "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("", "OPCLabs.KitServer.2",
"SimulateEvents.ConditionState1.AttributeValues.15400963", 123456);
easyDAClient.WriteItemValue("", "OPCLabs.KitServer.2",
"SimulateEvents.ConditionState1.AttributeValues.15400968", "Some string value");
easyDAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", true);
Console.WriteLine("Processing event notifications for 10 seconds...");
Thread.Sleep(10 * 1000);
easyAEClient.UnsubscribeEvents(handle);
}
// Notification event handler
static void easyAEClient_Notification(object sender, EasyAENotificationEventArgs e)
{
if (!e.Refresh && (e.Event != null))
{
// Display all received event attribute IDs and their corresponding values
Console.WriteLine("Event attribute count: {0}", e.Event.AttributeValues.Count);
foreach (KeyValuePair<long, object> pair in e.Event.AttributeValues)
Console.WriteLine(" {0}: {1}", pair.Key, pair.Value);
}
}
}
}
}
Regards
Please Log in or Create an account to join the conversation.
About querying value from the OPC DA, I have already tried it without success. Is it the good solution to read an item inside an alarm Event ?
Thanks again
Vincent
Please Log in or Create an account to join the conversation.
So, you are right in thinking that there should be something better in place already for this kind of requirement, and it is indeed the mechanism of event attributes. They are basically additional data pieces that can be supplied with each event. Whether or not you will be able to use it in your case depends on the actual OPC Server, because it is the OPC Server that defines which attributes are provided; there are only recommendations in the OPC specs as to what attributes can be/should be supported, but nothing mandatory. For example, the specification recommends in Appendix B that the level condition alarm should support a CV (Current Value) attribute.
This is how it works:
The OPC-A&E server provides a set of Event Categories. Each category provides a set of Event Attributes. Each attribute has a numerical ID, a data type, and a description. You can obtain this information either from the OPC server documentation, or by calling QueryEventCategories method on the EasyAEClient object.
Because collecting, generating or further processing of attributes with each event can be resource-consuming, by default no attributes are actually supplied by the server. You need to specify the attributes you are interested in when making a subscription. Some overloads of the SubscribeEvents method on thye EasyAEClient object have 'returnedAttributesByCategory' input argument. By filling it in, you can specify, for each event category, which attributes you are interested in. After subscribing in this way, the event notification will contain the attribute values.
I hope this helps.
Please Log in or Create an account to join the conversation.
Sent: Friday, July 13, 2012 11:13 AM
To: Zbynek Zahradnik
Subject: RE: OPC Alarms&Events
Hi Zbynek
We are looking for a solution to get the opc tag value (current value or CV) when an alarm is fired.
We have seen a AttributeValues property in the Event object.
Could it be useful for our needs ?
If yes how do we configure this (actualy, the collection is Empty)
Thanks
V.
Please Log in or Create an account to join the conversation.
- Forum
- Discussions
- QuickOPC-Classic in .NET
- OPC Alarms&Events
- obtaining tag value when alarm is fired, and AttributeValues property