LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a "Get Cluster Names" VI?

Thanks, yes, that is correct, I want to read each cluster value from an ini file according to name, and therefore need the names as strings.

With Yamaeda's solution, my code now looks like the picture.

I'll also check out your library, thank!

 

 

0 Kudos
Message 11 of 22
(2,684 Views)

Thanks, Yamaeda, works 100%

 

 

ClusterReadByName.PNG

 

Message 12 of 22
(2,675 Views)

@pvz wrote:

Thanks, Yamaeda, works 100%

 

 

ClusterReadByName.PNG

 


But not recursively though. So to allow a cluster in the cluster, you need to do a bit more work. 

 

That's not too difficult, but choices need to be made. My library simply ignores cluster names, and uses section_key from the label to put values in sections and keys. That is a choice. But it can be changed by tweaking some parameters (reg.ex.) or by implementing a child class to change the default behavior.

 

Of course, if you don't anticipate recursive clusters, it will do the trick.

 

The moment you put other types in the cluster, you're also in trouble.

Message 13 of 22
(2,670 Views)

True.

 

All the cluster values need to be of the same type, and in my code I must also make sure that the type of the default constant (-1) that I give to the Read Key.vi is of that same type. Not flexible. I'm sure your library is better. I'll try that out, I'm just working quickly to finish my current development iteration to get it deployed in the field, then I'll check our library out and substitute with more flexible code.

 

Thanks!

0 Kudos
Message 14 of 22
(2,654 Views)

Now your cluster is fixed size, due to Array to Cluster, and although it should work for now it can become a problem if the Channel Map changes size. A small tweak you can do is to 'reverse' the operations you start with, so after reading the ini-file (shouldn't it be a double?) you can convert it to a variant so you build an array of variants, much like you started with, then after the loop you can use Variant to Data and convert that array to a Channel Map. That way it should be more general and dynamic. 🙂

/Y

 


@pvz wrote:

Thanks, Yamaeda, works 100%

 

 

ClusterReadByName.PNG

 


 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 15 of 22
(2,639 Views)

@Yamaeda wrote:

A small tweak you can do is to 'reverse' the operations you start with, so after reading the ini-file (shouldn't it be a double?) you can convert it to a variant so you build an array of variants, much like you started with, then after the loop you can use Variant to Data and convert that array to a Channel Map. That way it should be more general and dynamic. 🙂

/Y

IIRC, the reverse is not that easy. And array of variants can't be converted to a cluster with Variant To Data, the variant tools don't (or didn't used to) set the values, just the types.

0 Kudos
Message 16 of 22
(2,632 Views)

wiebe@CARYA wrote:

@Yamaeda wrote:

A small tweak you can do is to 'reverse' the operations you start with, so after reading the ini-file (shouldn't it be a double?) you can convert it to a variant so you build an array of variants, much like you started with, then after the loop you can use Variant to Data and convert that array to a Channel Map. That way it should be more general and dynamic. 🙂

/Y

IIRC, the reverse is not that easy. And array of variants can't be converted to a cluster with Variant To Data, the variant tools don't (or didn't used to) set the values, just the types.


True, you have to use Flatten/Unflatten to string for that. That's how I've made my general recursive 'write cluster as ini'-file. 🙂

It works like this:

Cluster flatten.png

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 17 of 22
(2,583 Views)

@Yamaeda wrote:

 That's how I've made my general recursive 'write cluster as ini'-file. 🙂


Me too. Now does yours work for classes (raising the bar)?

0 Kudos
Message 18 of 22
(2,578 Views)

wiebe@CARYA wrote:

@Yamaeda wrote:

 That's how I've made my general recursive 'write cluster as ini'-file. 🙂


Me too. Now does yours work for classes (raising the bar)?


Haha, I've never thought about that use case, so probably not. 🙂 It does work with arrays as main input though, not only clusters.

I do have a 'custom section' input, so I could use the class/instance name as section and write the data cluster as normal I guess ...

So how to you organize that? Class name as section, data fields as properties? What about multiple instances of a class, do they all have unique names?

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 19 of 22
(2,574 Views)

@Yamaeda wrote:..

So how to you organize that? Class name as section, data fields as properties? What about multiple instances of a class, do they all have unique names?

/Y


For my setup (it's online), I simply look at labels. They should be section_key by default (changeable with a reg.ex. or overridable). If a label doesn't match, it's ignored. It will recurse over nested classes, but arrays of classes (and cluster) are not allowed.

 

There's an input of the VI that allows prepending\postpending a string to each label. So one could simply label persistent values with an underscore, and then specify the section name on a higher level.

 

That's just one way... It's not really hard to make this, but making it general applicable and flexible is very hard.

 

It's not a technical problem, it's about API design and requirements (*sigh* hate when that happens). That's why the library is OO... I can easily change it's behavior with inheritance. To some extend of course, but a lot more can be done, and easier, compared to a group of normal VIs.

0 Kudos
Message 20 of 22
(2,569 Views)