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.
MacOS and Windows10 data change subscription
You should never do such thing as while(i) ;
It takes too much CPU, and - as it is happened here - can prevent other threads (which are firing the events) from running.
Best regards
Please Log in or Create an account to join the conversation.
while (i);
with
while (i)
{
System.Threading.Thread.Sleep(1);
};
Subscription works also on MacOS. Strange thing.
Please Log in or Create an account to join the conversation.
Output from Win10 and Mac OS attached.
The code is exactly samo on both of platforms.
Robert
Please Log in or Create an account to join the conversation.
I apologize for delayed reply.
Do the subscriptions work when you use our examples and connect to our public UA demo server?
Can you please add a handler to the static EasyUAClient.LogEntry event, and post here a capture of the events generated when running your test?
Thank you
Please Log in or Create an account to join the conversation.
I have tried another library Opc.UaFx and very simillar demo code works.
But we have bought QuickOPC license so I would prefer use it.
Thank you.
This is demo from Opc.UaFx library which works:
using Opc.UaFx;
using System;
using Opc.UaFx.Client;
using Opc.UaFx.Client.Classic;
static void HandleDataChanged(
object sender,
OpcDataChangeReceivedEventArgs e)
{
// Your code to execute on each data change.
// The 'sender' variable contains the OpcMonitoredItem with the NodeId.
OpcMonitoredItem item = (OpcMonitoredItem)sender;
Console.WriteLine(
"Data Change from NodeId '{0}': {1}",
item.NodeId,
e.Item.Value);
}
var client = new OpcClient("opc.tcp://192.168.2.6");
client.Connect();
OpcSubscription subscription = client.SubscribeDataChange(
"ns=6;s=::Main:OPC_Photo_ID",
HandleDataChanged);
subscription.PublishingInterval = 10;
bool i = true;
while (i){
//OpcValue idPhoto = client.ReadNode("ns=6;s=::Main:OPC_Photo_ID");
//Console.WriteLine("Value: {0}", idPhoto);
System.Threading.Thread.Sleep(1000);
}
client.Disconnect();
Please Log in or Create an account to join the conversation.
As a note, SubscribeDataChange always returns a handle ID - it is not dependent on whether the operation actually succeeds - this is intentional, because if something is wrong with the connection at that moment, it may become OK later, and this way your code does not have to do any reconnection logic.
Question: How do you know that the "[...] callback function [..] is not invoked on data change"? Because, in your code, there is a branch (for failures) that has the Console.WriteLine commented out:
//Console.WriteLine("*** Failure: {0}", eventArgs.ErrorMessage);
The first thing to do would be is to uncomment this line.
Best regards
Please Log in or Create an account to join the conversation.
The code is very simply and subscribe for data change of one item.
On both platforms client.SubscribeDataChange returns good handle ID.
If I try to read item directly via EasyUAClient.SharedInstance.ReadValue, value is read properly on both platforms.
But callback function does not work on MacOS and is not invoked on data change.
Can you help me? The code is attached.
On MacOS I am using target platform .NET 5 via NuGet QuickOPC 5.60.107 on Win also using target .NET 5 and NuGet QuickOPC 5.60.107
Thank you.
Robert
using System;
using OpcLabs.EasyOpc.UA;
namespace SimpleCapture
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.Run();
}
#region member functions
void Run()
{
//Initialize OPC communication
// Instantiate the client object
var client = new EasyUAClient();
try
{
//Quick OPC Client
UAEndpointDescriptor endpointDescriptor = "opc.tcp://192.168.2.6";
UANodeDescriptor nodeDescriptorPhotoID = "ns=6;s=::Main:OPC_Photo_ID";
Console.WriteLine("Subscribing to OPC_Photo_ID...");
// The callback is a lambda expression the displays the value
int nodeHandle = 0;
nodeHandle = client.SubscribeDataChange(endpointDescriptor, nodeDescriptorPhotoID, 10,
(sender, eventArgs) =>
{
if (eventArgs.Succeeded)
{
Console.WriteLine("Value: {0}", eventArgs.AttributeData.Value);
//photoName = eventArgs.AttributeData.Value.ToString();
}
else
{
//Console.WriteLine("*** Failure: {0}", eventArgs.ErrorMessage);
}
});
}
catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
bool i = true;
while (i) ;
}
#endregion
}
}
Please Log in or Create an account to join the conversation.