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.

How can I subscribe to a 2D Array OPC DA-Item?

More
14 Jan 2024 14:04 #12521 by support

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

More
14 Jan 2024 13:08 #12520 by mut9bu
Thank you, that was the solution, sorry for disturbing in the weekend. :)

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

More
14 Jan 2024 13:02 #12519 by support
You need to cast the Value to the expected type. Try this (I have not tested it, let me know if it works; if it does not, I will correct it). I have intentionally written it in 3 separate statements, but it can be shortened to one, if preferred - the working variables are not actually necvessary.
var arrayValue = (object[,])e.Vtq.Value;
object elementObject = arrayValue[0, 11];
string elementString = (string)elementObject;

The shortened form would be something like
string elementString = (string)(((object[,])e.Vtq.Value)[0, 11]);

This is a standard C# stuff, not truly related to QuickOPC.

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

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

More
14 Jan 2024 12:50 #12518 by mut9bu
Hello, sorry for disturbing you again:

Exactly at this point (accesing e.Vtq.Value as array) I have a problem:

I mean if I try to acces to e.Vtq.Value by index (as below), it gives me the Error "Error CS0021 Cannot apply indexing with [] to an expression of type"

string element_of_array = e.Vtq.Value[0,11];

Could you give a simple example how to acces the "e.Vtq.Value" as array?

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

More
12 Jan 2024 14:24 #12517 by support
Hello.
Yes, this is truncated, intentionally.. The ToString() method is not meant to provide full representation of an object in all cases.

You should not be converting the Vtq to a string, for the purpose of processing it.

Simply access the Vtq.Value as an array. You can index it easily, and it will have all the elements, no truncation.

Best regards

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

More
12 Jan 2024 13:37 #12516 by mut9bu
It's OK for me to extract the data in my own code. But here I get following problem:

When I read the 2D Array and write the result (e.Vqt) to the console line, I get the item in expected 2D Array format like following:

[6, 14] {{1, 1, 0, UPS battery failure., 45303.5347450463, ...}, {1, 1, 0, UPS battery failure., 45303.1925877778, ...}, {1, 1, 0, UPS battery failure., 45302.850599537, ...}, {1, 1, 0, UPS battery failure., 45302.5089953241, ...}, ...} {Object[,]} @2024-01-12T12:51:47.031; GoodNonspecific (192)

Here the Array-Item should have 6 lines and 14 columns. But as you see there are just four lines {XXXX} parts (the rest two is truncated with ...). And also just 5 columns (data in {} with comma seperated) are shown, the rest ist again truncted with ....

I have asked this to Bosch Rexroth (manufacturer of the CNC machine and OPC DA server. They mean that the OPC DA client may be truncating the rest.

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

More
11 Jan 2024 13:45 #12515 by support
Hello,

thanks for the answer. So yes, it is a 2D=array. However, what I wrote about OPC DA does apply. You need to extract the necessary pieces in your code on client side, unless there is a vendor-specific way. OPC DA specification has no way to specify this in itself.

Best regards

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

More
11 Jan 2024 13:42 #12514 by mut9bu
Hello
When I requested type with e.Vtq.Value.GetType() it returns System.Object[,]

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

More
11 Jan 2024 13:35 #12513 by support
Hello,

OPC-DA does not have a standard way of accessing/subscribing to parts of an array (OPC UA has that). If there is some way to do it, it would be vendor specific, so you need to consult with the server vendor.

In addition, are you sure that the item really returns an array? I found it weird that you wrote ".....is shown as one merged string". Can you verify the type by displaying e.Vtq.Value.GetType() ?

Best regards

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

More
11 Jan 2024 12:58 - 11 Jan 2024 13:24 #12512 by mut9bu
Hello
I am subscribing to a multidimension (2D) Array OPC DA-Item of a remote OPC DA Server (CNC Machine)
The rows of the item show the active Error messages on the CNC machine line by line (each row is a seperate Error message)
The columns of the item show the components of the Error message. For example column-1=Error class; column-2=Error source; column-3=Error-Text.....

When I subscribe to such an item with code below I get all the Error lines and and all the components of each error line, but it is shown as one merged string.

How can I access to the rows (Error Lİnes) columns (Error Components) of such a 2D array item?
using (var client = new EasyDAClient())
            {
                client.ItemChanged += client_Main1_ItemChanged;
                client.SubscribeMultipleItems(
                    new[] {
                            new DAItemGroupArguments(ip, "OPC.IwSCP.1",IndraMotion_MTX_P70,System.MessageStore,1,1,-1,0, 1000, null),                           
                        }                    
                    );
            }
 
public void client_Main1_ItemChanged(object sender, EasyDAItemChangedEventArgs e)
        {
            if (e.Succeeded)
            {
                item_value = e.Vtq.ToString();
                // Here I get all the Error Lines (rows) and the Error Components (columns) in one merged string.
            }
            //
            else
            {
                Console.WriteLine($"{e.ErrorMessageBrief}");
            }
         }
Last edit: 11 Jan 2024 13:24 by support.

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

Moderators: support
Time to create page: 0.070 seconds