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.

Reading MultipleItems

More
26 Mar 2014 06:12 - 26 Mar 2014 06:13 #1780 by support
Replied by support on topic Reading MultipleItems
There are two ways to achieve this.

1.

The ReadMultipleItems input arguments and the results are arrays where the elements with the same index belong together. I.e. (symbolically) results[0] is a result for args[0], results[1] is a result for args[1], etc. You can therefore write something like this:
        DAVtqResult[] sectVtqResults = m_edac.ReadMultipleItems(sectArgArray);
 
         for (int i = 0; i < sectArgArray.Length; i++)
         {
            string itemId = sectArgArray[i].ItemDescriptor.ItemId;
            DAVtqResult vtqResult = sectVtqResults[i];
            // ...
         }


2.

There is a State object in each DAReadItemArguments, and it gets copied to each DAVtqResult by the ReadMultipleItems method. You can fill the State with whatever you need, e.g. the item descriptor (or item ID, or anything else). Using this approach, the code may look like this:
        DAReadItemArguments[] sectArgArray = argumentArray2
            .Select(args => 
                new DAReadItemArguments(
                    args.ServerDescriptor, 
                    args.ItemDescriptor, 
                    new DAReadParameters(),
                    args.ItemDescriptor))
            .ToArray();
 
        DAVtqResult[] sectVtqResults = m_edac.ReadMultipleItems(sectArgArray);
 
 
        foreach (var vtqResult in sectVtqResults)
        {
            string itemId = ((DAItemDescriptor)vtqResult.State).ItemId;
            // ...
        }

Best regards
Last edit: 26 Mar 2014 06:13 by support.
The following user(s) said Thank You: netasp

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

  • netasp
  • Topic Author
  • Visitor
  • Visitor
25 Mar 2014 19:46 #1779 by netasp
Replied by netasp on topic Reading MultipleItems
The code above works great and I just have a quick follow up question, do this:

DAVtqResult[] sectVtqResults = m_edac.ReadMultipleItems(sectArgArray );

I can get the Vtq but the ItemId is not available to me at this level? because I want to take the Vtq along with the itemId and log them into a database? or should I have another array object to hold the ItemIds?

Thanks

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

More
25 Mar 2014 18:57 - 25 Mar 2014 19:59 #1778 by support
Replied by support on topic Reading MultipleItems
The exception you are getting indicates that at least one array element in the input array is null (in fact, they are all null, as they are not being filled in by the code).

You can convert the SubscribeMultipleItems arguments to arguments for ReadMultipleItems e.g. like this:
            DAReadItemArguments[] sectArgArray = argumentArray2
                .Select(args => 
                    new DAReadItemArguments(args.ServerDescriptor, args.ItemDescriptor, new DAReadParameters()))
                .ToArray();


I hope this helps
Last edit: 25 Mar 2014 19:59 by support.
The following user(s) said Thank You: netasp

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

  • netasp
  • Topic Author
  • Visitor
  • Visitor
25 Mar 2014 18:06 - 25 Mar 2014 18:22 #1777 by netasp
Reading MultipleItems was created by netasp
hi,
I would like to know how to read ALL subscribed tags? I can't get anywhere with the ReadMultipleItems(). Here is my code:
EasyDAClient m_edac = new EasyDAClient();
 
DAItemGroupArguments[] argumentArray2 = new DAItemGroupArguments[2];
            argumentArray2[0] = new DAItemGroupArguments(m_OPCMachineName, m_OPCServerName, itemIdTrigger, m_OPCUpdateRate, m_OPCObjectState);
            argumentArray2[1] = new DAItemGroupArguments(m_OPCMachineName, m_OPCServerName, itemIdCycleCount, m_OPCUpdateRate, m_OPCObjectState);
 
            m_edac.SubscribeMultipleItems(argumentArray2.ToArray());

Then when 1 specific tags changes, I want to read all subscribed items and pass them to a stored procedure, I have about 200 items to log to the database. Can someone show me how to read all subscribed items in the server? If I do the following, I get a null exception error:

DAReadItemArguments[] sectArgArray = new DAReadItemArguments[2];
DAVtqResult[] sectVtqResults = m_edac.ReadMultipleItems(sectArgArray); --> blows in here with the following error:
Precondition failed.: Contract.ForAll(argumentsArray, elem => elem != null) Null element in argumentsArray.
Parameter name: Null element in argumentsArray.

SubscribeMultipleItem takes an array of type DAItemGroupArgument and
ReadMultipleItems takes an array of type DAReadItemArgument and you can't cast from one to another and you can't read Items by creating a new array object?


Let me know
Thanks
Last edit: 25 Mar 2014 18:22 by netasp.

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

Moderators: support
Time to create page: 0.052 seconds