LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Enum vs ring

In the driver development guide, it says

 

Choose a text ring to represent values that do not have clear two state values (recommanded). 

 

Is ring preferred over enum in this case?  If so, why is that?  Does that mean I should use a ring if I have more than 2 values? 

 

If I have 0, 1, 2, 3, 4, why could it be recommaded to use a ring instead of enum?  It seems like a enum would work pretty well.  What are the pros and cons in this case?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 6
(4,419 Views)

Enum is a type def and can be connected to a Case structure where you'll see the enum names. Rings are a value array and can be changed in run time. Rings can also be given any value, whereas Enums automatically number from 1-X in step 1.

 

Just recently i've used Rings in a calibration program where i fill the list with nominal values and give the choices their actual value. What's the benefit? Choosing 120V in the text ring sends 120 as output from the control.

 

Enums make for prettier code, but not being able to change it in run time is a big drawback.

 

So, enums are a better choice if the program allows it, i'd say.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 6
(4,412 Views)

Yeah, I agree that enum is a better choice, but why does the guideline prefer a ring instead? 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 3 of 6
(4,409 Views)

 


@jyang72211 wrote:

Yeah, I agree that enum is a better choice, but why does the guideline prefer a ring instead? 


 

Enum is enumerated type and good choice in cases such as building state machines or in situations with "fixed cases". Usually enum used in connection with typedef. You can't modify enum in run-time. Ring is good in situation when items not defined or should be changed at runtime - you can do almost anything:

 

screenshot.png

Andrey.

 

Message 4 of 6
(4,386 Views)

I guess we should narrow down the use case to the driver level, otherwise we just repeate the endless comparissons between enum and ring.

At a driver level, there are two points I'd throw in for the ring:

* The advantage of propagating changes in the code via a type def'ed enums can be ignored, as you release a finished driver for your product (most likley encapsulating a finished dll).

* Other languages support 'enums' that aren't sequential. So it's easier to work with rings to map to values as 0, 1275, 14567. As an example look at the Excel ActiveX interface.

 

My personally prefered solution is to have a type-cast vi thats converting the enum to the numbers required by the dll/ActiveX/...

This adds an abstraction layer (operation/parameter->numerical code), which I think is good.

 

But another issue to have in mind, you can 'merge' such string-based rings:

Lets say:

OpA -> 1

OpB -> 2

OpC -> 22

where developed for module X (1,2) and Y (22), when you now come up with module Z that reuses (2, 22)...

 

Felix

Message 5 of 6
(4,378 Views)

Thanks!

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 6 of 6
(4,352 Views)