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.

ItemChanged handler (after upgrade from 5.12)

More
13 Jan 2016 05:27 #3758 by support
The last QuickOPC version for that was 5.23. It was build for .NET 3.5 and could be used in 3.5 or 4.0. I can send you a download link if you like. Your license will work with it. But we no longer support it officially.

I suppose that you know that Microsoft support for .NET 4.0 and, in fact, also 4.5 and 4.5.1, has ended just yesterday. That effectively leaves only 3.5, and then 4.5.2 and higher, as supported frameworks.

Best regards

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

More
12 Jan 2016 21:49 #3757 by lpoyner
This is huge change since our main application is sadly still in .NET 4.0

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

More
12 Jan 2016 18:01 #3756 by support
Good. Out of my head, I think it is e.Arguments.ItemDescriptor.ItemId.

Note that the example code is intentionally oversimplified. e.Vtq may be null in case of errors; your code should check e.Exception for non-nullness first.

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

More
12 Jan 2016 17:39 #3755 by lpoyner
Sorry, found it in another project

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

More
12 Jan 2016 17:32 #3754 by lpoyner
In the event handler for ItemChanged (client-ItemChanged) we are trying to put the e.Vtq.Value into cache array. In 5.12 the ItemId was under e.ItemDescriptor, like this:

dataCache[e.ItemDescriptor.ItemId] = e.Vtq.Value;

Now ItemDescriptor is gone, so where might I find ItemId for this value?

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

More
12 Jan 2016 17:22 #3753 by lpoyner
I found a lead to what you mentioned in the example under ConsoleEvents, I'll give that a try

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

More
12 Jan 2016 17:10 #3752 by support
Here is an example (one of the examples that come with the product):

using OpcLabs.EasyOpc.DataAccess.OperationModel;
// ReSharper disable CheckNamespace
// ReSharper disable InconsistentNaming
#region Example
// This example shows how subscribe to changes of multiple items, and unsubscribe from one of them.
using JetBrains.Annotations;
using OpcLabs.EasyOpc.DataAccess;
using System;
using System.Threading;
 
namespace DocExamples
{
    namespace _EasyDAClient
    {
        class UnsubscribeItem
        {
            public static void Main()
            {
                using (var easyDAClient = new EasyDAClient())
                {
                    easyDAClient.ItemChanged += easyDAClient_ItemChanged;
 
                    int[] handleArray = 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 30 seconds...");
                    Thread.Sleep(30 * 1000);
 
                    Console.WriteLine("Unsubscribing from the first item...");
                    easyDAClient.UnsubscribeItem(handleArray[0]);
 
                    Console.WriteLine();
 
                    Console.WriteLine("Processing item changed events for 30 seconds...");
                    Thread.Sleep(30 * 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);
            }
        }
    }
}
#endregion
// ReSharper restore InconsistentNaming
// ReSharper restore CheckNamespace


Note that it is 'static' only for the purpose of the sample code, in your app it probably won't be.

Best regards

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

More
12 Jan 2016 17:03 #3751 by lpoyner
No, cannot change that var declaration because when I do, it says:

Argument type 'method group' is not assignable to parameter type 'opcLabs.EasyOpc.DataAccess.OperationalModel.EasyDAItemChangedEventArgs'

How do you instantiate an event handler for ItemChanged?

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

More
12 Jan 2016 16:36 #3750 by support
Yes, correct selection in your case is the non-generic class in EasyOpc.DataAccess.OperationModel .

I have not tested it, but can't you change
var itemChangedEventHandler = new EventHandler<EasyDAItemChangedEventArgs>(this.OPCItemChanged);

to
var itemChangedEventHandler = new EasyDAItemChangedEventHandler(this.OPCItemChanged);

Provided that OPCItemChanged has proper argument types, it should be possible to simply write
opc.ItemChanged += OPCItemChanged;

Best regards

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

More
12 Jan 2016 16:23 #3749 by lpoyner
Can you please help. This is how we set up item changed event handler in 5.12:

opc = new EasyDAClient();
var itemChangedEventHandler = new EventHandler<EasyDAItemChangedEventArgs>(this.OPCItemChanged);
opc.ItemChanged += itemChangedEventHandler;

The EasyDAItemChangedArgs is no longer in OpcLabs.EasyOpc.DataAccess. EasyOpc.DataAccess.Generic has EasyDAItemChangedEventArgs<T> and EasyOpc.DataAccess.OperationModel has EasyDAItemChangedEventArgs. So I selected second one because we don't have a <T>, but then the last line will not work, not assignable. It says opc.ItemChanged is of type EasyOpc.DataAccess.EasyDAItemChangedEventHandler.

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

Moderators: support
Time to create page: 0.057 seconds