LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating enum from list

I would like to update a number of enums in my system using some sort of script, that would take c++ files, find enums in them and convert these enums into LV eums.

I'm pretty sure we can get to the point where we have the elements of the enum in some sort of list, and the c++ enums will start at 0 and have a continuous stepsize of 1. The problem is to turn this list into a LV enum.

Anyone have any ideas?

//Martin
0 Kudos
Message 1 of 10
(11,241 Views)
I don't think you can do that. A LabVIEW enum includes the string names as part of the data type. You cannot change the data type of a control or indicator programatically.

If you use a TEXT RING or a MENU RING, then you can get approximately the same behavior - you can set the STRINGS property of either to an array of string values. The difference is that the VALUE of the control is a numeric, not an enum. If you wire the control to a CASE statement for example, the cases would be 0,1,2, where a true enum would have "A", "B", "C" cases.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 10
(11,241 Views)
I've written the attached VIs to convert a C enum statement into a LabVIEW enum. If the values are no consecutive, a lookup table VI is also created to convert the enum to its related value.


LabVIEW, C'est LabVIEW

Message 3 of 10
(11,243 Views)
I'm impressed.  Very nice indeed.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 10
(10,889 Views)
It looks like you were able to create the enum programmatically. I don't have C code, so I wasn't able to use your example.

Is there a way to statically create an enum with non-contiguous values?
0 Kudos
Message 5 of 10
(10,230 Views)


Derek.Mayer wrote:

Is there a way to statically create an enum with non-contiguous values?

No, the enum data type does not save index values with the values.
 
To do what you want you can create a conversion VI like JP does in his code.

___________________
Try to take over the world!
Message 6 of 10
(10,208 Views)
You can create an Enum from a list of values.

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 7 of 10
(10,203 Views)


@Derek.Mayer wrote:
It looks like you were able to create the enum programmatically. I don't have C code, so I wasn't able to use your example.

Is there a way to statically create an enum with non-contiguous values?


LabVIEW enums are always consecutive. If you want sparse enums you have to use the ring control instead where you can assign names to each value but those names are not part of the LabVIEW datatype.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 10
(10,191 Views)

I add the c enum to Labview enum from the link. I updated it to 2012 and added name of the enum.

 

Julien

0 Kudos
Message 9 of 10
(6,662 Views)

I have been developing a slightly more elaborate one, though no way universal, as only the C compiler would be.

My one can scan .h files for either

#define PREFIX_SOMETHING value /* comments */

 or

PREFIX_SOMETHING = value /* comments */

 where value is an integer in either decimal or hex notation, duplicate values are discarded, and definitions can be filtered by PREFIX.

The results are used to populate a ring control, which may eventually be copied to a typedef for perusal.

 

Enrico

0 Kudos
Message 10 of 10
(6,379 Views)