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
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.

More
19 Mar 2019 19:53 #7235 by support
Hello.

Regarding the first issue: You can either convert the whole array, or you can process it element by element (as you are doing in the second example) and do the conversion on each element. Converting the whole array can be done in multiple ways, I personally would prefer something like
Int32 arrayValue = value.Cast<Int32>().ToArray;
(where Cast<> and ToArray are from the System.Linq namespace).

Regarding the second issue, I would also intuitively expect that the low array boud is 0 and the high array bound is 1, so at first glance your code looks correct to me. But we cannot know for sure what the server has returned. Please inspect what the bounds of the returned array are, by retrieving its .GetLowerBound(0) and .GetUpperBound(0).

Regards

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

More
19 Mar 2019 19:31 #7234 by Šilhavý

Šilhavý wrote: Hello again after a month.
I finally got into some C# programming (just basics), so I try to run IndexRange example from your site, but no luck.

Program is able to connect to server, can see the node but cannot cast the object:

imgur.com/a/Z417HAR

So I understand it cannot "convert" the object in Object to Integer (because this type of object cannot be converted) or there is other error

Change Int to Object (and maybe it is bullshit, because I dont quite understatd the DataTypes in C# - even when they should be the same like in VB):

imgur.com/a/9bFqKbF

So where I am wrong, or where to start.

The link with example of IndexRangeList is good, but it is requred to understand all the methods and attributes used there.
Sure I will continue reading it and try to understand.


PS: Console:
imgur.com/a/ICUHUsc

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

More
19 Mar 2019 19:24 #7233 by Šilhavý
Hello again after a month.
I finally got into some C# programming (just basics), so I try to run IndexRange example from your site, but no luck.

Program is able to connect to server, can see the node but cannot cast the object:

imgur.com/a/Z417HAR

So I understand it cannot "convert" the object in Object to Integer (because this type of object cannot be converted) or there is other error

Change Int to Object (and maybe it is bullshit, because I dont quite understatd the DataTypes in C# - even when they should be the same like in VB):

imgur.com/a/9bFqKbF

So where I am wrong, or where to start.

The link with example of IndexRangeList is good, but it is requred to understand all the methods and attributes used there.
Sure I will continue reading it and try to understand.

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

More
19 Feb 2019 06:31 #7101 by support
The value is not a string. You are displaying the result object *as a string*, and QuickOPC formats it, and in the process it only shows several first elements of long arrays, so that the resulting string is readable by humans.

The actual value is array of integers, and there is the whole array present, not just part of it. If you write code to get the length of the array, you will see that it is much longer, and you can get all its elements by index.

Regards

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

More
18 Feb 2019 20:04 #7100 by Šilhavý
Thanks for fast reply.

In the future I think we will be using C#, JavaScript or other (when I learn it..) I will go through the guide and try to understand it.
Whe I use .Read method it gives me part of the string of the array:

imgur.com/a/z7KXiTD

Is this the case of too long string?

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

More
15 Feb 2019 07:52 - 15 Feb 2019 07:52 #7092 by support
Hello.

There are basically three options to read an array element in OPC UA:

1. Read the whole array, and then extract the desired element(s) by the means of the programming language or tool you are using. Advantage: It always works. Disadvantage: It is ineffective with larger arrays.

2. Pass IndexRange as part of the read request. The server then extracts the requested element(s) and returns only them to the caller. This is the preferred method. Advantage: It is efficient. Disadvantage: Not all OPC UA servers support it.

3. Use some server-specific means of accessing arrays elements. That is, some servers expose the array, and then, also additional nodes (with different Node IDs) for individual elements of the array. Disadvantage: Only works with specific server, and you need to know how (from the server documentation).

What you have attempted to do looks like method #3. With this I can offer no help, because it depends on the server. It is unlikely to work with integer Node IDs. Such servers usually expose string Node IDs (those with "s="), which then allow to put in the syntax they have chosen. Most likely your server does not support it anyway, so you won't be able to find the syntax at all.

If your arrays are small, go with method #1, it's the easiest.

If they are not, go for method #2 (and hope that the server support it; if not, you'll have to revert to #1). For it, first read this: opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...tml#Index%20Range%20Lists.html .

The examples provided are currently in C# and VB.NET, but the principles are the same in VBA. But because there are no method overload in COM, you'll have to use ReadMultipleValues, and pass in the "argument" objects, and also construct the UAIndexRangeList object from the scratch (and not using helper static methods like .OneDimension, because there are no static methods in COM). If you run into problems, let me know and I wil either advise, or prepare the example in VBA.

S pozdravem
Last edit: 15 Feb 2019 07:52 by support.

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

More
14 Feb 2019 19:27 #7091 by Šilhavý
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 ?

Thanks for your reply.

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

Moderators: support
Time to create page: 0.067 seconds