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
15 Nov 2021 13:25 #10348 by koggaccio

support wrote: ...For example, in VB6 or VBA, someArrayValue(elementIndex) is the syntax to access an element of an array...


Solved (not elegant code but it works) in this way (using opc.uafx.client in VB):

Dim nome_nodo_opc As String = "opc.tcp://MANUTENZIONE:48010" 'nodename declaration
Dim var_array_test = "ns=2;s=Demo.Static.Arrays.Int64" 'variable contain the tag to be read
Dim client As New OpcClient(nome_nodo_opc) 'declaring opc client
client.Connect() 'client connection
Dim variabilearraytest = client.ReadNode(var_array_test) 'reading tag array
client.Disconnect() ' disconnection
Dim intValues As Int64() = CType(variabilearraytest.Value, Int64()) 'array values on int64
LabelValueIndex2.Text = intValues.GetValue(2) 'writing on a textlabel the value of the array index (in this case "2" equivalent to the third value of the array)
LabelValueIndex0.Text = intValues.GetValue(0) 'writing on a textlabel the value of the array index (in this case "0" equivalent to the first value of the array)
... and so on...
Thanx

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

More
15 Nov 2021 12:55 #10347 by support
Hello.

If the node contains an array, then you can call ReadValue and you will get the whole array back. You can then either process it as a whole, or you can use the instruments of your language/tool to extract elements from it. For example, in VB6 or VBA, someArrayValue(elementIndex) is the syntax to access an element of an array..

If the server supports it, you can read just a selected range of elements from an array-typed node. Examples: opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...ments%20from%20an%20array.html .

Some servers may provide separate nodes that correspond to individual array elements. Which nodes they are would be server specific. If that is what you are looking for (asking for "syntax"), your question is misplaced - you need to consult the server documentation or ask the server's vendor.

Best regards

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

More
15 Nov 2021 12:05 #10346 by koggaccio

Šilhavý wrote: Hello.
Can you help me with getting data out of the UA Server (Arburg machine) using EasyOPCUA.
Single value works fine. ut how can I get the full array or just given part of the array?:
Single:
mClient.ReadValue("opc.tcp://1.1.1.1:4880/Arburg", "ns=2;i=212365") OK

And value, which is an array?:
mClient.Read("opc.tcp://1.1.1.1:4880/Arburg", "ns=2;i=12345;2") or [2] or ,2 ?
.


same problem... have you solved?

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

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.

Moderators: support
Time to create page: 0.065 seconds