03-07-2019 04:05 AM
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!
03-07-2019 04:44 AM
Thanks, Yamaeda, works 100%
03-07-2019 05:00 AM - edited 03-07-2019 05:04 AM
@pvz wrote:
Thanks, Yamaeda, works 100%
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.
03-07-2019 07:51 AM
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!
03-07-2019 09:24 AM
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%
03-07-2019 09:48 AM
@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.
03-18-2019 03:31 AM
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:
/Y
03-18-2019 04:00 AM
@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)?
03-18-2019 04:06 AM - edited 03-18-2019 04:08 AM
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
03-18-2019 04:50 AM
@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.