- Posts: 2
- Thank you received: 0
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
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.
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.
Š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.
var valueAsArray = (object[]) value;
var valueElement0 = (UAAttributeData)valueAsArray[0];
var valueElement0AsArray = (object[]) valueElement0.Value;
dynamic innerElement1 = valueElement0AsArray[1];
var innerElement1Value = (Int32)innerElement1.Value;
Best regards
Please Log in or Create an account to join the conversation.
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.
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.
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.
object[] value2 = {value};
I think you should change that line to
var value2 = (object[])value;
Int32[] arrayValue = value2.Cast<Int32>().ToArray();
Please Log in or Create an account to join the conversation.
Attachments:
Please Log in or Create an account to join the conversation.
I think you also need to press the "Insert" or "Insert All" button.
Please Log in or Create an account to join the conversation.