Professional OPC
Development Tools

logos

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

More
19 Apr 2021 09:14 #9614 by support
Hello.

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.

More
18 Apr 2021 16:50 #9613 by rsicak
When I replace on MacOS

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.

More
18 Apr 2021 15:40 #9612 by rsicak
I Add LogEntry to the code and hook function.
Output from Win10 and Mac OS attached.
The code is exactly samo on both of platforms.
Robert
Attachments:

Please Log in or Create an account to join the conversation.

More
17 Apr 2021 09:16 #9610 by support
Hello,
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.

More
14 Apr 2021 15:17 - 17 Apr 2021 09:14 #9609 by rsicak
Hallo, I have uncomment the suggested line but nothing happend.
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();
Last edit: 17 Apr 2021 09:14 by support. Reason: code formatting

Please Log in or Create an account to join the conversation.

More
10 Apr 2021 09:27 #9593 by support
Hello.

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.

More
09 Apr 2021 11:10 - 10 Apr 2021 09:23 #9590 by rsicak
Hallo, I have the same code in Visual Studio 19 for Win 10 and VisualStudio for Mac on BigSure.
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
    }
}
Last edit: 10 Apr 2021 09:23 by support. Reason: formatting

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.054 seconds