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.
- Forum
- Discussions
- Feature Requests & Product Improvement Ideas
- How can I subscribe to a 2D Array OPC DA-Item?
How can I subscribe to a 2D Array OPC DA-Item?
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
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
Please Log in or Create an account to join the conversation.
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.
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.
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.
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.
When I requested type with e.Vtq.Value.GetType() it returns System.Object[,]
Please Log in or Create an account to join the conversation.
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.
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}");
}
}
Please Log in or Create an account to join the conversation.
- Forum
- Discussions
- Feature Requests & Product Improvement Ideas
- How can I subscribe to a 2D Array OPC DA-Item?