LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating sparse enums in CVI for LabVIEW

LabVIEW, for some reason, does not support creating or editing sparse enums.

NI, however, describes a process to import sparse enums created in CVI.

I want to try to hack this and see if I can create an editor for these, but I don't have CVI, so I was hoping someone could create a couple of these sparse enums and upload them. I'm not sure if this matters, but I have access to LV 7.0 and 7.1, so I'd appreciate something in parallel versions.

Examples:

[value, label

1, one
4, four
6, six
2, two
]

[value, label

6, apple
24, orange
18, pear
27, peach
0, grape
]

Thank you.

___________________
Try to take over the world!
0 Kudos
Message 1 of 17
(5,632 Views)
Well, I followed steps 1 to 7 of the instructions in your link, using your sample data. I don't have LabView, so I couldn't go any further. Attached fp file was created with CVI 7.0 (the only version I have). (It is inside a zip file: the forum would not accept a file with the .fp extension...)
 
Good luck!
 
JR
0 Kudos
Message 2 of 17
(5,617 Views)

Thank you, but what I got there are rings, which can be sparse in LV.

Can you do the same with an enum?


___________________
Try to take over the world!
0 Kudos
Message 3 of 17
(5,608 Views)

Or did you already use an enum and this process simply converts it to a ring?

The article is from before LV 7.0 was released (which I believe was the first version which had sparse rings), so it's possible it never did produce sparse enums, but I saw people say that they did use this process to create sparse enums in LV. I suppose it is possible they did not remember correctly.


___________________
Try to take over the world!
0 Kudos
Message 4 of 17
(5,606 Views)
Looks like I misunderstood what you wanted...
 
In straight C, your 'sparse enum' could be simply written as follows:
 
enum fruit {
    grape = 0,
    apple = 6,
    pear = 18,
    orange = 24,
    peach = 27
};
 
But I though you wanted something more complex - ie the Ring control in the link that you pointed to. Is this not so?
 
JR
0 Kudos
Message 5 of 17
(5,601 Views)

In LabVIEW, a ring is simply a numeric control which has a list of display strings. The strings and values in the control can be changed at any time since the control is a simple numeric.

An enum is a special numeric data type where the value includes both an integer and a string. The main advantage is when using case structures - wiring an enum to a case structure gives you the enum strings in the case structure, like this:

Changing the enum values after connecting it to the case structure will propogate accordingly. Wiring a ring control to a case structure is just like wiring any other numeric - you need to use numeric values.

The problem is that to set up enums you need to use the editing interface and that does not allow changing the values of the enum - they must be 0,1,2,3,4, etc. In my hacking I did manage to change the order of these, but not create a sparse one, and that's why I want the one from CVI. As I said, it is possible that this only applies to rings, but I was hoping it worked for enums as well. How do you place an enum into a control?


___________________
Try to take over the world!
0 Kudos
Message 6 of 17
(5,593 Views)
Well, we would probably use a Ring control Smiley Tongue or a List Box - both of these allow arbitrary Label/Value pairs, with a wide choice of data types (int, char, string, double etc.) so not restricted to just numbers. The fp editor (at least at CVI 7.0) does not support List Box controls so this looks like a dead end. Can LabView import CVI UIR files? This would give a larger field to experiment in.
 
JR
0 Kudos
Message 7 of 17
(5,587 Views)

LabVIEW has three basic types -

  • Ring - a numeric control with display strings. The value is the numeric value associated with the string you selected.
  • Combo box - a string control with a list of display strings.
  • Enum - a numeric type with fixed embedded strings.

I'm guessing the only way to import is using the process descibed there and explicitly refers to sparse enums, so I was hoping that would be simple, but I also see that the process says to use a ring control. I take it there is no other way to insert an enum into a control?


___________________
Try to take over the world!
0 Kudos
Message 8 of 17
(5,575 Views)

Looking at your description of a LabView enum it seems to have a correlation to a simple C string table, which can be defined like this:

    char *strings [] = {"Zero", "One", "Two", "Three", "Four", "Five"};

    n = 2;
    Print (strings [n]);    // Match the string to a numeric value

So this also gives a direct mapping of strings to sequential numeric values, where no gaps are allowed. With such a simple C primitive, CVI does not really need a specific GUI control to manipulate the resulting data.

JR

0 Kudos
Message 9 of 17
(5,554 Views)

If my C understanding is correct, you can go back at any point in your code and change the array to hold other strings, so that's just a string array. An enum has constant strings and values as part of its data type, just like you can't set an int variable to be 3.6.

The LV enum is not necessarily limited to an ordered list. In my hacking I did manage to create an out of order enum ("three, one, zero, two"; 3, 1, 0, 2), but not one which includes numbers which are not sequential from 0. I was hoping this process would help.


___________________
Try to take over the world!
0 Kudos
Message 10 of 17
(5,549 Views)