LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible for a cluster to be set to allow variable data input?

I posted this question at the bottom of a different thread but it looks like that one has died out plus this is really a separate question. So I hope no one minds me starting a new thread here.

 

I made the program Convert2Matfile.vi which I intend to use as a SubVI in other programs. How I want this program to work is I would like to bundle up double any quantity of 1D/ 2D arrays and or numeric values and pass them to this tool which will then convert what ever it is sent to an appropriate variable in a matlab file using the element name as the matlab variable name.

 

The issue I am having here, is that currently I have a 1D, 2D and a numeric value sitting in the cluster definition on my front panel of the Convert2Matlfile.vi. Because I have this, the code is looking for every cluster to be structured exactally like the one I have in the front panel. How do I source that code more generically? See the photo below of the broken wire. Error message is as follows;

 

You have connected two arrays of different dimensions.

The dimension of input cluster -> array #2 is 1.

The dimension of Cluster In -> array 2 is 2.

 

So clearly it is looking for the Cluster to be exactally like the one it is looking for. Is there any way to do this more generically so it can accept any type of cluster of any quantity of values so long as they meet my criteria?

0 Kudos
Message 1 of 8
(2,878 Views)

You can use apolymorphic VI which will allow you to wire the specific type to the subVI. This will be done at edit time and is not able to switch at run time. You could also use a variant input with a type specifier. Your subVI would use the type identifer to properly decode the variant to the corect data type.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 8
(2,858 Views)

Well it looks like I will likely need to treat this as a variant. Unfortunatley for me I hate dealing with Variants in LabVIEW likely more as a result as a lack of understanding when it comes to how to deal with them than anything. My stratedgy I would think should be as follows figure out how many items are in my variant that are either a numeric, a 1D or a 2D array. Then one by one go to each of those values. If say it is a numeric get the numerical value, get the label name and send it over to my convert to Matlab program one by one.

 

So that would be the theory behind how I would try to do this. Now how the heck do I actually do anything along those lines? I can't even figure out how to get the number of elements in my variant. I would have thought the "Get Variant Attribute function" would be a great place to start. So I made up the exploreVariant.vi below. See the images of the code plus the front panel after execution. I followed the instructions from the following location;

http://zone.ni.com/reference/en-XX/help/371361J-01/lvhowto/retrievingattribsfromvard/

 

  1. Add the Get Variant Attribute function to the block diagram.
  2. Wire variant data to the variantinput of the Get Variant Attribute function.
  3. Leave the name input and the default valueinput of the Get Variant Attribute function unwired.
  4. Right-click the names output and select Create»Indicatorfrom the shortcut menu.
  5. Right-click the values output of the Get Variant Attribute function and select Create»Indicatorfrom the shortcut menu to retrieve the values associated with each attribute.
  6. Run the VI.

Even after following the instructions above nothing shows up in either the names or values collumn. So how the heck do I actually do what I want to do? I just can't seem to figure out how to index through a variant at all.

 

Download All
0 Kudos
Message 3 of 8
(2,814 Views)

You have a complete misunderstanding of what variant attributes are. You need to actually set an attribute before you can get it. In the example below I only showed how to retrieve a single value. To retrieve the other values individually simply change the name you want to retrieve and the type wired to Variant to Data.

 

Variant Attributes.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 8
(2,808 Views)

Hi Mark,

 

Thanks for the quick reply, I see what you are doing there but now that brings me back to my initial problem. In this case I don't know what I will be feeding my convert2mat program. One time I could hand it the 4 items below. The next time it may just be 10 1D arrays. So what is the best and easiest way to handle the variety of variables such as this? I suppose I could also pass the SubVI all the expected names in and then do it with some bigger for loop, but I would have thought there should be a way to stuff a whole bunch of either random variables into a single cluster or variant and do exactally what I am trying to do.

 

Thanks,

 

Adam

0 Kudos
Message 5 of 8
(2,805 Views)

@adamsdaq wrote:

Hi Mark,

 

Thanks for the quick reply, I see what you are doing there but now that brings me back to my initial problem. In this case I don't know what I will be feeding my convert2mat program. One time I could hand it the 4 items below. The next time it may just be 10 1D arrays. So what is the best and easiest way to handle the variety of variables such as this? I suppose I could also pass the SubVI all the expected names in and then do it with some bigger for loop, but I would have thought there should be a way to stuff a whole bunch of either random variables into a single cluster or variant and do exactally what I am trying to do.

 

Thanks,

 

Adam


Which would bring me back to my original suggestion of using a polymorphic VI.

 

Or if you want to use variants name your variables meaningful names. For your data use a cluster which consists of a typedefed ENUM which designates the variable type and a variant for the data itself. Pass the name of the desired variable to your convert VI. That VI would retrieve the variable by name, decode the cluster getting the data type of the variable and use that for a case selector to decode the data itself.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 8
(2,800 Views)

Hi Mark,

 

When it comes to using polymorphic VI's my understanding of a polymorphic would be that I need to predefine each particular condition I may run in a file. My goal with this tool is that I just bundle anything I want inside of my program into one big cluster, or variant and dump it into the subvi where it becomes a matlab file. Can a polymorphic handle that or don't I need to define and layout in advance any and all combinations I would be feeding into it?

 

As for naming the variables inside a variant meaningful names, eventually that would be what will happen but that too could vary depending on the program I am running it in. For example in one use I may have variables being Accelerometer Ch #1, Ch#2, dt, and t0 all being variables, another use it may be temperature, Ch #1,#9 etc... It shouldn't really matter. I hope you understand what I am trying to do. Can this actually be done? If not I suppose I could just wire my initial convert2mat tool up as needed inside of my program, but I would have hoped there was an easy way to just bundle a bunch of clusters and send it on in.

0 Kudos
Message 7 of 8
(2,796 Views)

At some point you must define your data types that you will support. I provided you with a generic method to use the variants using a cluster containing the data and the data type. You need a generic framework to support generic sets of variables. The method I proposed will do that provided you define all the base types you will support. If you want 6 variables in one case and 4 in another you would add six variables to your variant attribute variable list in the first case and four in the second. It will support any number and combination of your predefined base types.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 8
(2,791 Views)