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.

× If you are developing in .NET, but are using the OPC-UA (OPC Unified Architecture), please post in the QuickOPC-UA category instead.

How to subscribe to multiple OPC DA items, when amount of variables is changing?

More
20 Dec 2023 12:02 #12493 by mut9bu
The following user(s) said Thank You: support

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

More
20 Dec 2023 11:28 #12492 by support
Hello.
It seems to me that you can simply do
client.SubscribeMultipleItems(dAItemGroupArguments .ToArray());
Is that what you were looking for?
The following user(s) said Thank You: mut9bu

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

More
20 Dec 2023 10:54 - 20 Dec 2023 11:13 #12491 by mut9bu
Hello

My console app has following arguments:
        public string ip_address = Environment.GetCommandLineArgs()[1];
        public string item_no = Environment.GetCommandLineArgs()[2];        
        public string item_1 = Environment.GetCommandLineArgs()[3];
        public string item_2 = Environment.GetCommandLineArgs()[4];
        public string item_3 = Environment.GetCommandLineArgs()[5];
        public string item_4 = Environment.GetCommandLineArgs()[6];
        public string item_5 = Environment.GetCommandLineArgs()7];
        public string item_6 = Environment.GetCommandLineArgs()[8];
        public string item_7 = Environment.GetCommandLineArgs()[9];
        public string item_8 = Environment.GetCommandLineArgs()[10];
        public string item_9 = Environment.GetCommandLineArgs()[11];
        public string item_10 = Environment.GetCommandLineArgs()[12];

Due to the item_no parameter I tried to define a list of items:
         List<DAItemGroupArguments> dAItemGroupArguments = new List<DAItemGroupArguments>();
 
         public void item_list()
         {
           for(int i = 0; i < Convert.ToInt16(item_no); i++)
            {
                dAItemGroupArguments.Add(new DAItemGroupArguments(ip, server, Environment.GetCommandLineArgs()[i+3], 1000, null));
            }
         }

So I should use always this list (or something similar) in the client.SubscribeMultipleItems(...) expression.
Last edit: 20 Dec 2023 11:13 by support.

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

More
20 Dec 2023 10:42 #12490 by support
Hello.

It's easy to do. You just need to convert what you have into the form expected by the method. But I cannot answer it without knowing in which form (object types, their properties etc.) you get your items. Please share a piece of code illustrating that.

Regards

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

More
20 Dec 2023 10:27 - 20 Dec 2023 10:40 #12489 by mut9bu
Hello

In my C# .net framework 4.7.2 app I am subscribing to multiple OPC DA items. But my app is called from a parent app with arguments. That means, the number of items and the item definitions come from the argument parameters and changing each time.

Normally I subscribe to 3 items with following code. How should I modify my code, so that I can sometimes for example subscribe to 2 items sometimes to 8 items , depending on the argument parameters? With other words I would like to use a List of items for the client.SubscribeMultipleItems expression. But couldn't find the correct way for this.
using (var client = new EasyDAClient())
            {
                client.ItemChanged += client_Main1_ItemChanged;
                client.SubscribeMultipleItems(
                    new[] {
                            new DAItemGroupArguments(ip, "OPC.IwSCP.1",item_def1, 1000, null),
                            new DAItemGroupArguments(ip, "OPC.IwSCP.1",item_def2, 1000, null),
                            new DAItemGroupArguments(ip, "OPC.IwSCP.1",item_def3, 1000, null),
                        }                    
                    );
            }
 
public void client_Main1_ItemChanged(object sender, EasyDAItemChangedEventArgs e)
        {
            if (e.Succeeded)
            {
                item_value = e.Vtq.ToString();
            }
            //
            else
            {
                Console.WriteLine($"{e.ErrorMessageBrief}");
            }
         }
Last edit: 20 Dec 2023 10:40 by support.

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

Moderators: support
Time to create page: 0.060 seconds