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.

Get data from ARRAY Excel VBA

More
26 Mar 2019 10:00 - 26 Mar 2019 10:01 #7277 by support
Great. Try this please ('value' is what you get from the ReadValue method on the node you indicated):
            var valueAsArray = (object[]) value;
            var valueElement0 = (UAAttributeData)valueAsArray[0];
            var valueElement0AsArray = (object[]) valueElement0.Value;
            dynamic innerElement1 = valueElement0AsArray[1];
            var innerElement1Value = (Int32)innerElement1.Value;
Your desired value will be in 'innerElement1Value'. The whole thing can be written in one statement, but I used multiple lines to show how we gradually extract the part(s) that we want.

Best regards
Last edit: 26 Mar 2019 10:01 by support.

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

More
26 Mar 2019 08:47 #7276 by Šilhavý
Thanks.
What I want now is to get values of the last shot - the last line - the whole array or better separated.
So when I look on the picture of DataFeed client:
EndPointDescriptor is fine.
NodeID: ns=2;i=245533
And I want to get just the second value (15357) and store it as an Integer.

What would be the syntax here, please?

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

More
25 Mar 2019 20:59 #7274 by support
You need to make it first clear to yourself what you want.

In the array you have received in the first image, you clearly get a value which is an array that has one element, and that one element is then an array that has 19 elements which are values of different types. This is apparent both in the screenshot from DataFEED client (where you have even underlined the types: Int32, String, Single), and it the VS debugger. You are already receiving that from QuickOPC. It's just an issue of processing it correctly in your code. But you need to have an idea of what you want to do. If the array contains values if different types, you cannot cast them all to Int32. I guess that they have different semantics anyway, so you need to know which element means what, know their expected types, and cast them separately. In addition, they come as Opc.Ua.Variant, which is a structure where the actual value is further below. Expanding that in the debugger will nicely show you which member you need to get.

If you have somebody who knows C# around, and you can explain what you actually want to achieve, it is a matter of minutes to do this.

I can also help, but you need to specify the correspondence between what you are reading from the server, and what you want to get in your program - that is, which elements are of interest, and where you want to store them to and in which form (which variable, expected data type).

Regards

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

More
25 Mar 2019 18:57 #7273 by Šilhavý
Hello again after weekend.
I have made corrections, but still invalid cast:


I have tried server simulator from OPCFoundation, where different types of arrays are present and no problem with anything. I think there is a problem with the node itself (or the datatype) but I cannot find it.
I do not know if you know the Arburg injection machines... there is a production protocol, it looks like this (on the machine display):


And when I want the list of all values (each line, each shot, machine can hold 99 lines so the Ubound 98 is right):


And screen from the DataFEED client so maybe you will see where possible error is. Couldn't the different datatypes be the issue (I think not, when we cannot get even the bound of the Array - IF it is Array):
Attachments:

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

More
22 Mar 2019 09:16 #7260 by support
The line
object[] value2 = {value};
makes no sense. You are creating an array with single element which again is the array you have received. No wonder that than the bounds are 0 and 0 (there is a single element), and that the element (which is then an array itself) cannot be cast to Int32.

I think you should change that line to
var value2 = (object[])value;
Having that, you can then simplify the following line:
Int32[] arrayValue = value2.Cast<Int32>().ToArray();
Best regards

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

More
21 Mar 2019 16:16 #7257 by Šilhavý
Cannot see the attachement, my fault probably, my apology.
But this image is maybe better.
Attachments:

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

More
21 Mar 2019 16:16 #7256 by support
The attachment is missing.
I think you also need to press the "Insert" or "Insert All" button.

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

More
21 Mar 2019 15:44 #7255 by Šilhavý
Cast is not valid - see attachment.

Lower and Upper bound is 0 - but I think the syntax is wrong.

The UAReadArguments constructor should see the values when it is initialised?

I have read nearly the whole Fundamentals of your Guide and whole Identifiing Information in OPC-UA, starting to understand the basics (of C).
.

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

More
20 Mar 2019 16:46 - 20 Mar 2019 16:47 #7246 by support
Hello, no problem.

GetLowerBound and GetUpperBound will work on any array-typed variable, so I believe you do not need any additional namespace declaration for that. So if you have g.
object[] value = ......;
the you can do value.GetLowerBound(0) and value.GetUpperBound(0) - but not if 'value' was declared as scalar ("object value = ......");

Same with the .Cast<> etc. - it works on arrays (well, it works on any IEnumerable) - but not on scalars.

Referring to the screenshot you have sent, converting to array of Int32, would be done something like
Int32[] arrayValue = ((object[])value).Cast<Int32>().ToArray()

(I have not tested it, but hope it is right).
But I would expect you obtain the bounds before doing the .Cast<> - because the code above would "normalize" the lower bound to 0, and shift the upper bound if needed. This may be good thing (if you want to be sure that the lower bounds is always 0, for further processing), or a bad thing (if you wanted to know what the lower bound actually was, in the array delivered by the server).

If you later want to post images (screenshots), please do so using the "Attachments" button below the forum editor box.

Best regards
Last edit: 20 Mar 2019 16:47 by support.

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

More
20 Mar 2019 13:55 #7238 by Šilhavý
Hello, I am total noob in this so I have to ask:

1. What namespace is the GetL/HBound member of? Or on what should I call it? On the converted arrayValue?

2. Still cannot convert - Do I use it right in declarations (to be honest - Linq is the very next chapter in my tutorial of C#... )?:

imgur.com/a/mCG2MRZ

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

Moderators: support
Time to create page: 0.309 seconds