Professional OPC
Development Tools

logos

Xmlserver and EasyDAClient.SharedInstance.SubscribeItem

More
15 May 2018 16:20 #6338 by goosvanbeek
Thank you, it works as expected now!

Best regards,
Goos van Beek.

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

More
15 May 2018 16:01 #6337 by support
You are right, I apologize. The example on www.opclabs.com is not correct and we will fix it. There needs to be an additional 'state' argument at the end, which you can use to distinguish the callbacks (can be null).

A complete functional example can look like this:
// This example shows how subscribe to changes of a single item in an OPC XML-DA server 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
    {
        partial class SubscribeItem
        {
            public static void CallbackLambdaXml()
            {
                // Instantiate the client object
                var client = new EasyDAClient();
 
                Console.WriteLine("Subscribing...");
                // The callback is a lambda expression the displays the value
                client.SubscribeItem(
                    "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", 
                    "Dynamic/Analog Types/Int", 
                    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());
                            }
                        },
                    state: null);
 
                Console.WriteLine("Processing item changed events for 10 seconds...");
                Thread.Sleep(10 * 1000);
 
                Console.WriteLine("Unsubscribing...");
                client.UnsubscribeAllItems();
 
                Console.WriteLine("Waiting for 2 seconds...");
                Thread.Sleep(2 * 1000);
            }
        }
    }
}
Best regards
The following user(s) said Thank You: goosvanbeek

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

More
15 May 2018 12:37 #6334 by goosvanbeek
Hello support,

The code you suggested unfortunately doesn't work at my side.
www.opclabs.com/products/quickopc/opc-specifications/opc-xml-da
// The callback is a lambda expression that displays the value 
EasyDAClient.SharedInstance.SubscribeItem(
    "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Int", 1000,
    (_, args) => Console.WriteLine(args.Vtq.Value));

Method 'SubscribeItem' has 5 parameter(s) but is invoked with 4 argument(s)
https://www.screencast.com/t/vX1gCILPv


Regards,
Goos van Beek

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

More
15 May 2018 08:51 #6332 by goosvanbeek
Thanks for the clear explanation. I used the code from this page: www.opclabs.com/ and wasn't aware that it could be different for a xml server.
I will test this later today and I expect no problems with it anymore.

Best regards,
Goos van Beek

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

More
15 May 2018 05:51 #6330 by support
You are passing wrong arguments to SuscribeItem. You have an additional "" as the first argument; that needs to be removed.

Compare your code carefully with e.g. www.opclabs.com/products/quickopc/opc-specifications/opc-xml-da .

In addition, note that the callback code is simplified for the purpose of making the example short. Your actual code should check the Exception property before accessing Vtq. See:

opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...AttributeData%20property).html

and

opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...r%20UAAttributeData.Value.html

Best regards
The following user(s) said Thank You: goosvanbeek

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

More
14 May 2018 19:35 #6329 by goosvanbeek
Thanks for your quick reply.

This is the stacktrace:

" bij SharedInstanceTest.Program.<>c.<Main>b__0_0(Object _, EasyDAItemChangedEventArgs eventArgs) in C:\\KUKA\\DEV\\SharedInstanceTest\\SharedInstanceTest\\Program.cs:regel 16\r\n bij OpcLabs.BaseLib.Widgets.NotifyingWidget.<>c__DisplayClass45_0`1.<CallbackAction>b__0()\r\n bij OpcLabs.BaseLib.Widgets.NotifyingWidget.SafeCallback(String name, Action action)"

See also the image links below (unfortunately in dutch)

https://www.screencast.com/t/NttWKjg4Ht

https://www.screencast.com/t/hi8cSzCtqeb

Regards,
Goos.

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

More
14 May 2018 19:11 #6328 by support
SharedInstance is not related to the issue.

Is eventArgs.Exception null? If it is not, what is the exception it contains?

Best regards

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

More
14 May 2018 18:47 #6327 by goosvanbeek
Hello support,

I'm trying use EasyDAClient.SharedInstance.SubscribeItem on a xml server. I can subscribe my items, but the vtq returns null. Am I doing something wrong or isn't it possible to use an shared instance subscrubtion with a (KUKA)xml server
?
Using SharedInstances with an local OPCDA server works fine.
EasyDAClient.SharedInstance.SubscribeItem(
                "", "http://172.31.1.145:8081/DA", "RobotMSG.messageinfo", 1000,
                (_, eventArgs)=>Console.WriteLine(eventArgs.Vtq.Value));


Best regards,
Goos van Beek

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

Moderators: support
Time to create page: 0.207 seconds

      

 Recommend this on Google