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-UA in .NET
- Reading, Writing, Subscriptions
- How to subscribe and process changes to a boolean tag
How to subscribe and process changes to a boolean tag
You might be getting a "bad quality" as a first update. Before accessing e.AttributeData.Value, I would check e.AttributeData.HasValue. Your current code might work as well, but I still recommend this.
Best regards
Please Log in or Create an account to join the conversation.
private void easyUAClient1_DataChangeNotification(object sender, EasyUADataChangeNotificationEventArgs e)
{
// if exception, do nothing.
if (e.Exception != null)
{
return;
}
// if no attribute data, do nothing.
if (e.AttributeData.Value == null)
{
return;
}
// try casting attribute data as a booleana and if false, seam detect reset event, do nothing.
try
{
if (Convert.ToBoolean(e.AttributeData.Value) == false)
{
return;
}
}
// if unable to cast to boolean, not what we need to be processing, do nothing.
catch
{
return;
}
Please Log in or Create an account to join the conversation.
when subscribing....
easyUAClient1.SubscribeDataChange(epd, node, 10000);
easyUAClient1.DataChangeNotification += easyUAClient1_DataChangeNotification;
string seamDetectTagChanged = "SeamDetected";
easyUAClient1.SubscribeMultipleMonitoredItems(new[] {
new EasyUAMonitoredItemArguments(seamDetectTagChanged, "opc.tcp://10.0.16.82:4096",
"ns=2;s=[default]Test Data/Test Data/Sam_Coater_Seam_Detect", 1000)
});
in the event handler...
private void easyUAClient1_DataChangeNotification(object sender, EasyUADataChangeNotificationEventArgs e)
{
// if exception, do nothing.
if (e.Exception != null)
{
return;
}
object state = e.Arguments.State;
try
{
if (Convert.ToString(state) != "SeamDetected")
{
return;
}
}
catch
{
//if not seam detected state, return.
return;
}
//continue to do processing of detected seam...
Please Log in or Create an account to join the conversation.
If Exception is null, the event carries data.
If you are subscribed to multiple items, you can distinguish them
1. By information contained in eventArgs.Arguments - for example, eventArgs.Arguments.NodeDescriptor contains information about the node involved. An example for that:
opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...es%20for%20data%20changes.html
2. Faster and more generic approach with many items is to pass some information in when you are subscribing - for it, there is a State argument or property, and then get eventArgs.Arguments.State and use whatever information you find there. So with each notification you get the State that was used when subscribing. The State can be any 'object', and it can therefore point right to something that identifies the item for you.
Regards
Please Log in or Create an account to join the conversation.
easyUAClient1.DataChangeNotification += easyUAClient1_DataChangeNotification;
to create an event handler. However, that event handler is getting called multiple times, when the program first starts up, and then when I change a Boolean tag, it is getting called several times. I need to know how to interrogate and only go through the logic of the event handler when it is a change in Boolean value of the tag I need to monitor. Can you provide a generic example of how to test in the event handler for a change to a single tag like wrapping if logic around it or doing a return right at the top? Or even a line I can use to know what is causing the event? Thanks.
Please Log in or Create an account to join the conversation.
A note to the code: The UserName and Password properties are rarely, if ever, used with OPC UA. Certainly never with "opc.tcp:" scheme. In theory they might be used to authenticate access to the resource when HTTP is used, but I have never seen it in practice. The user authentication is done on OPC UA level instead, using the UserIdentity property.
Best regards
Please Log in or Create an account to join the conversation.
easyUAClient1.DataChangeNotification += easyUAClient1_DataChangeNotification;
Please Log in or Create an account to join the conversation.
EasyUAClient easyUAClient1;
UAEndpointDescriptor epd = new UAEndpointDescriptor();
UANodeDescriptor node = new UANodeDescriptor();
easyUAClient1 = new EasyUAClient();
epd.UserName = "opcuauser";
epd.Password = "password";
epd.Port = 4096;
epd.Host = "10.0.16.82";
node = new UANodeDescriptor("ns=2;s=[default]Test Data/Test Data/Sam_Coater_Seam_Detect");
//try to subscribe to change events.
easyUAClient1.SubscribeDataChange(epd, node, 500);
//does not seem to be firing, set a breakpoint in debug and change tag value but seeing event.
static void easyUAClient1_DataChangeNotification(object sender, EasyUADataChangeNotificationEventArgs e)
{
// Display value
// Remark: Production code would check e.Exception before accessing e.AttributeData.
Console.WriteLine(e.AttributeData.Value);
}
Please Log in or Create an account to join the conversation.
- Forum
- Discussions
- QuickOPC-UA in .NET
- Reading, Writing, Subscriptions
- How to subscribe and process changes to a boolean tag