LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PPL with external typedef as control - VIM alternatives?

Solved!
Go to solution

I'm trying to write a "System Configuration"-type class, which ideally has an API something like:

  • Add PSU (power supply object, map of "channel name" to channel index. I'd like the Channel Name to come from a typedef, ideally)
  • Set Voltage on Channel (name, numeric -> take the typedef'd name, convert to a PSU index and a channel index, carry out the operation via a separate PSU class)
  • Other similar PSU operations (name, whatever other inputs/outputs -> typedef'd name to PSU + Ch index, do operation, return results)

If I use a string for the names, then this is fairly straightforward - the Config class has an array of PSU classes (which can dynamic-dispatch) and manages them as by-value objects (considered DVRs but prefer to just write "after adding to config, don't use the object anymore" in the info... hopefully I'll remember not to do that!), and then a map of PSU Array index, Ch index (from the map passed to Add PSU, which is String -> Int).

cbutcher_4-1677639711865.png

However, if I want to use a typedef'd enum, then my class needs to know the enum first. I don't have that information at build-time for the PPL (in practice, I probably could, but then I might as well not have the Config class, since I can't have a different config for a new experiment/setup/whatever).

 

Format Into String in a malleable VI would solve this (with some checking that the name isn't reused, by being passed two different enums at different call-sites, etc). But I can't see how to package that nicely with a PPL - I can put the VIM alongside, but now it needs to always be used next to the VI I actually want to call (I can't put it inside, because then I don't know what control type I need for the actual VI I care about (Set Voltage, for example)). In this case, the VIM only makes it a tiny bit smaller than using Format Into String, and I could just write a VI with a tiny icon to do that (in the calling application, specific to the/each enum, or VIM if multiple...) but I still end up placing twice as many VIs as I want in the calling application.cbutcher_2-1677639424343.png

I thought perhaps I could replace the String label for channels with the numeric value of the enum, and then have it coerce, but Maps don't allow that. I can use an array of clusters of numerics - maybe this is an option, but then I can't use two different enums in any situation (I could use Rings with non-sequential values, but then coordinating their values for different "providers" becomes a potential bear-trap...). At this point, I've lost most of the safety too, but it is more condensed (and full of red dots 😞 )cbutcher_0-1677638951642.png

What are the better solutions I didn't consider? (leaving aside "don't use a PPL"...)

Or, which would you choose? (Allowing "don't do anything like this at all, do this instead" 😛 )


GCentral
0 Kudos
Message 1 of 3
(885 Views)
Solution
Accepted by topic author cbutcher

If you make that input into a Variant, then pass in an enum you've never seen before, you can get the string value of the enum out of the Variant using the Variant Data Type Parsing Palette.  I've done it like this:

 

Kyle97330_0-1677690785958.png

Plus an alternate if a "String" or equivalent is passed in:

Kyle97330_1-1677690813605.png

 

Message 2 of 3
(845 Views)

Thanks, I considered variants but didn't know the pattern to get from enum to string (or indeed, value... Get Numeric Information was the VI I needed for this 🙂 )


GCentral
0 Kudos
Message 3 of 3
(818 Views)