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.

Example needed - subscribe to OPC item change event

More
18 Oct 2016 06:07 #4474 by den Bekker
Thank you,

This will put mme on track I think.

Regards,

Ruud

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

More
17 Oct 2016 14:08 #4473 by support
The simplest (although not very realistic) example is on our Web page: www.opclabs.com/products/quickopc/languages-and-tools/csharp .

Better examples: open the solution with C# Examples (from the Start menu), then look into the Console/DocExamples project. You will find there e.g. following examples:

1.
// This example shows how subscribe to changes of multiple items and display the value of the item with each change,
// using a callback method specified using lambda expression.
 
using System.Diagnostics;
using OpcLabs.EasyOpc.DataAccess;
using System;
using System.Threading;
 
namespace DocExamples
{
    namespace _EasyDAClient
    {
        class SubscribeItem
        {
            public static void CallbackLambda()
            {
                // Instantiate the client object
                var easyDAClient = new EasyDAClient();
 
                Console.WriteLine("Subscribing...");
                // The callback is a lambda expression the displays the value
                easyDAClient.SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Random", 1000,
                    (sender, eventArgs) =>
                        {
                            Debug.Assert(eventArgs != null);
 
                            if (eventArgs.Exception != null)
                                Console.WriteLine(eventArgs.Exception.ToString());
                            else
                            {
                                Debug.Assert(eventArgs.Vtq != null);
                                Console.WriteLine(eventArgs.Vtq.ToString());
                            }
                        });
 
                Console.WriteLine("Processing item changed events for 10 seconds...");
                Thread.Sleep(10 * 1000);
 
                Console.WriteLine("Unsubscribing...");
                easyDAClient.UnsubscribeAllItems();
 
                Console.WriteLine("Waiting for 2 seconds...");
                Thread.Sleep(2 * 1000);
            }
        }
    }
}
2.
// This example shows how subscribe to changes of multiple items and display the value of the item with each change.
using JetBrains.Annotations;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
using System;
using System.Threading;
 
namespace DocExamples
{
    namespace _EasyDAClient
    {
        partial class SubscribeMultipleItems
        {
            public static void Main()
            {
                using (var easyDAClient = new EasyDAClient())
                {
                    easyDAClient.ItemChanged += easyDAClient_ItemChanged;
 
                    easyDAClient.SubscribeMultipleItems(
                        new[] {
                            new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, null), 
                            new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, null), 
                            new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, null),  
                            new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, null)
                        });
 
                    Console.WriteLine("Processing item changed events for 1 minute...");
                    Thread.Sleep(60 * 1000);
                }
            }
 
            // Item changed event handler
            static void easyDAClient_ItemChanged([NotNull] object sender, [NotNull] EasyDAItemChangedEventArgs e)
            {
                Console.WriteLine("{0}: {1}", e.Arguments.ItemDescriptor.ItemId, e.Vtq);
            }
        }
    }
}

If you are more interested in code in some more specialized environment (such as Windows Forms - showing data as values of texboxes etc.), we have such examples as well - let me know.

Best regards

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

More
17 Oct 2016 13:50 #4472 by den Bekker
1) OPC Data Access

2) C#

Regards,

Ruud

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

More
17 Oct 2016 13:31 #4471 by support
Hello.

Please indicate

1) which OPC specification do you intend to use (OPC Data Access, or OPC Unified Architecture) - the principle is the same, but the actual example code differs somewhat,

2) which programming tool/language do you intend to use/prefer.

Thank you

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

More
17 Oct 2016 13:30 #4470 by support
From: B.
Sent: Monday, October 17, 2016 2:12 PM
To: Z.
Subject: ...

[...]

Which example shows me how to subscribe to change events of
the OPC item?

I can read the item when loading a form, but of course I want to update
the data the moment it changes on the PLC.

Best regards,

R.

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

Moderators: support
Time to create page: 0.055 seconds