04-08-2014 10:42 AM
Folks,
I am building a set of subvis for a customer who will provide their own interface and use that to call into one of my subvis.
There are many commands (a serial I/O application) to support. What I'm shooting for is an enumeration control for all commands so the customer can just add this to their front panel. As they choose a command this (among other inputs) is passed into my subvi.
The problem: in my subvi I can see each numeric value for a command (I have a driver to mimic the customer) as 0, 1, 2, 3
etc. In the case structure in my subvi I would like to be able to have each case refer to the name of each enum rather than raw numbers. So if the user on thier VI selects GetTemperature I want in my subvi case structure to use that same name,
GetTemperature, rather than 0 and so on.
This is all to simple a thing to do but I don't see the light (newbie gets bit again). I started out passing string to get the
ball rolling but I hate that.
I've been on the forums until my eyes glazed over.
The zip file has my project (of course it's broken because of a mix of integer/strings in a case statement). MiniMain.vi is
what I call the driver and Mila.vi is my subvi that eventually the customer will call into.
Any help would be greatly appreciated.
Dave
04-08-2014 11:01 AM - edited 04-08-2014 11:02 AM
Right click on the enum and select 'make type def.'. Then use that type def in all of your SubVIs and when you update in one place it will update in all of the other places as well. You can right click again and go to 'open type def.' to edit the enum options and save the type def as a control.
04-08-2014 01:27 PM
Thanks Sam. Took a short while but I'm good to go with type def.
But the real problem is: on my driver I will see the enum type names (good). When an enum is choosen I can see it come
over into my subvi as a value (0, 1, 2 etc, still good). I can wire this input to a case structure but the problem is now all I have
is a 0 or 1 or 2 or whatever in the subvi to plug into the case structure. I'm hoping there's a way to programmatically convert
the raw input (0,1,2 and so on) into the enum type names so I can use the enum type names in the case statements.
Is there a way to process the input value (the 0,1,2 etc) in the subvi back into the enum type names?
Thanks for any help
Dave
04-08-2014 02:45 PM
@dkl234 wrote:
Thanks Sam. Took a short while but I'm good to go with type def.
But the real problem is: on my driver I will see the enum type names (good). When an enum is choosen I can see it come
over into my subvi as a value (0, 1, 2 etc, still good). I can wire this input to a case structure but the problem is now all I have
is a 0 or 1 or 2 or whatever in the subvi to plug into the case structure. I'm hoping there's a way to programmatically convert
the raw input (0,1,2 and so on) into the enum type names so I can use the enum type names in the case statements.
Is there a way to process the input value (the 0,1,2 etc) in the subvi back into the enum type names?
It sounds like you made a type def, but didn't replace the front panel control on your subVI with that new type def. Right click the control and select Replace >> Select a Control and browse to where you saved the type def control. Now when you update the type def, all places that call that type def will also be updated, and you can wire that to a case and it will work with the names. Please post your code because all I am doing is guessing and having a VI I would know the problem and be able to give a better answer.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-08-2014 02:57 PM
This will convert a number back to an enum which you can then wire to the case structure. The important VI here is 'Type Cast' but it is very important to pass a U16 to the type cast function to correctly conver to enum. I am not sure why you are getting a number though, you would normally be able to pass the enum.
04-08-2014 03:29 PM
Thanks to you both Hooovahh and Michael.
Now I see how this enum thing goes together. I have to work it a bit more but I think it will come together fine.
I would never have guessed Michael's block diagram was the way to solve this. Just couldn't see how the enum
type def came into play.
Thanks again all for the help.
Dave
04-08-2014 03:32 PM
@Michael_78 wrote:
This will convert a number back to an enum which you can then wire to the case structure. The important VI here is 'Type Cast' but it is very important to pass a U16 to the type cast function to correctly conver to enum. I am not sure why you are getting a number though, you would normally be able to pass the enum.
No need to convert using type cast which can be dangerous if not done properly (as you illuded to). Instead use Coerce to Type which isn't on the palette, and might not be officially supported by NI but it is picking up speed.
Also to be fair I think Variant to Data works in various situations too.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-08-2014 03:39 PM
04-08-2014 03:41 PM
No need to be worried. Just like many features of LabVIEW you can use and abuse them to the point that unexpected things will happen. Just know when to use things (like Type Cast) and you can do very cool stuf. Like some times I have a cluster of random data, and I want to know how big it is in memory. You can use a type cast and cast the cluster to an array of U8 and you will get the number of bytes it takes to represent that cluster and its elements.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-09-2014 07:16 AM
That and, it shouldn't be necessary to type-cast (or convert) because you should be using the type-def everywhere (e.g. for going into SubVIs etc.) as Hooovahh suggested. The only reason to need to do what Michael has suggested is if you have been provided with a VI/Library that you can't change (because it's part of 3rd party driver or NI's palettes) and need to convert it to your own type def.