From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW APIs Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Having two problems with array scripting

I'd like to be able to receive a reference to any array and perform some processing on that array.  There are two operations that I'd like to be able to perform but haven't been able to find a way.

I can get the number of dimensions through a property node, and if I access the Value property and display it the variant display is of the form "[n]", "[nxo]", or "[nxoxp]" (for 1D, 2D, and 3D, respectively, where n, o, and p are integer values).  But there doesn't seem to be any way extract the size numbers so they can be used.  See the following snippet.

(Note that in the snipped below, the Array 3 terminal should really be a reference to Array 2. I'm not sure why generating a snippet changed the reference to a control. Perhaps a bug?)

Get Array Sizes.png

The second operation that doesn't seem to be working is trying to access existing array elements.  If I set the IndexVals property then access the value what I get isn't the actual contents of the indexed element.  The result I see after trying to read is an array of 3 elements containing a boolean false and empty string.  See the snippet below (same issue with the Array 3 terminal, should really be a reference to Array 2).

(Seems like this should work, since writing to an array does work this way, set the indicies, then the value and the specified element updates.)

(The reason the loop count is 3 is I thought this might provide a work around for the first issue by just indexing until hitting the end of the data.  But there's no indication that you've gone past the defined data, you just get back the default value.)

Read Array Element.png

0 Kudos
Message 1 of 6
(4,939 Views)

DAD, If you have the strictly typed reference from your array passed in you can get the value, number of cols and number of rows from a property node without using scripting. Number of dimensions is 1D, 2D etc.

When you create the snippet and your constant is changed to a control, the VI the reference is now what is on the control and this is no longer for that specific array from your BD, only the type info is present. You must now pass in the appropriate array ref to the VI.

Not sure why you are casting the reference form your array to the Array type? Are you looking for generic array info for various types and dimensions of arrays?

To get individual elements take the output of your value property and index it as you would any array. Or am I not understanding your intent? The index property changes the indices on the array control for display purposes and are not the index of a specific element.

Thanks, Rick

0 Kudos
Message 2 of 6
(3,575 Views)

Rick,

Let me start by explaining what my end goal is.  Most applications have some type of configuration data (either in an ini file or a database) that is read to control some aspect of it's operation.  Instead of my developers always creating VIs to read from the data source and populate a data structure (i.e. LabVIEW cluster), I'd like to create a tool that I can point at a cluster and have it break down the data organization and build a VI to read the corresponding values to populate the cluster.  That way all the developer needs to do is decide what data they need and run the tool to create the code.

A cluster of scaler values is easy.  It gets more complex when you add nested structures (i.e. cluster containing and array of ? or a cluster containing a cluster, etc.).  I've got everything working, including nested clusters, but arrays are turning out to be the tougher nut to crack because you need to determine the number of indicies (easy) the size (problem) and index into the array and look at the value in each element (problem).

Now, I agree it works if you have a strictly typed reference connected to the property node.  But I'm trying to create a VI in which I can pass in a reference to any VI, hence the cast to more generic Array type.

I don't have a constant on the block diagram that's getting changed when I create the snippet.  Here's what the original code looks like:

Snippet 2.PNG

Since the original control gets copied in the snippet, I don't see why it has to convert the reference to a new control.

I can't use the property node to access the array data and index its return to access the individual values because I don't necessarily know the number of indicies.  The code above doesn't really do what I need, it was just a test to see if I could read an element by specifying the indicies.  When I run it, I get the following result:

Access Array Elements.PNG

You can see that the output does not contain any of the input array values.  So specifying the indicies doesn't affect reading the value.  (As I originally mentioned, if you specify the indicies and set a value, it sets the element you indexed, but this doesn't seem to hold true for reading the value.)

Thanks,

DAD

0 Kudos
Message 3 of 6
(3,575 Views)

Correction, I'm trying to create a VI in which I can pass in a reference to any cluster, not any VI.

0 Kudos
Message 4 of 6
(3,575 Views)

DAD wrote:

 

Let me start by explaining what my end goal is.  Most applications have some type of configuration data (either in an ini file or a database) that is read to control some aspect of it's operation.  Instead of my developers always creating VIs to read from the data source and populate a data structure (i.e. LabVIEW cluster), I'd like to create a tool that I can point at a cluster and have it break down the data organization and build a VI to read the corresponding values to populate the cluster.  That way all the developer needs to do is decide what data they need and run the tool to create the code.

Interesting...how is this different than the Open-G Variant Config File functions? You can pass any kind of structure into those (as long as it's comprised of simple types, arrays, and clusters) and it'll write or read those elements to/from a .INI file. There's also MGI Read/Write Anything, which basically does the same job.

0 Kudos
Message 5 of 6
(3,575 Views)

David Staab wrote:

Interesting...how is this different than the Open-G Variant Config File functions? You can pass any kind of structure into those (as long as it's comprised of simple types, arrays, and clusters) and it'll write or read those elements to/from a .INI file. There's also MGI Read/Write Anything, which basically does the same job.

From the title I would have said, the difference would be that he wants to use scripting to create individual VIs for a particular cluster type to read and write the configuration data, but from the description it would seem he really just wants to recreate the OpenG Tools.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(3,575 Views)