LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Same Enum at multiple location

Solved!
Go to solution

1. Attached is state machine implementation example in chapter 8 of core 1, page 8-7. 2. Question is : how to create same enum at mutiple location. Like case here have two states: Start & configuration. When I create enum on front panel it will appear on bloack diagram as "Start" But in case structure there is another instance where enum shows "configuration" 3. How it is done? 4. Can it be done like if in future I change name "Start" in case to "Sta". It would automatically change at all places in current VI.

0 Kudos
Message 1 of 13
(6,099 Views)

An enum contains a list of options - in this case, the enum has options 'Start' and 'Configuration'. On the attached image of a block diagram, they are constants. This means that each instance can have a different selection from that list of options.

 

To ensure that future changes are reflected everywhere that the enum is used, you can convert it to a typedef.

---
CLA
Message 2 of 13
(6,093 Views)

Yup in reality all enums should be type defs.  That way updating them in one place will cause all the copies of it to be updated.  Here are a few links talking about type defs.

 

http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/creating_type_defs/

http://digital.ni.com/public.nsf/allkb/1B04FD6A11E6F17286256C6300588BFA

http://zone.ni.com/reference/en-XX/help/371361H-01/lvconcepts/custom_cont_ind_type/

 

Clusters are another data type that generally should be type def'd.

Message 3 of 13
(6,062 Views)

You have discovered the Need for Typedefs (as the previous responder noted).  Here's my procedure whenever I create an Enum:

  1. Drop an Enum control on your Front Panel.
  2. Right-click it, choose Edit, and populate it as best you can.
  3. Now right-click it again, and choose Make Type Def.  Nothing seems to happen, but don't panic ...
  4. Right-click a third time, and choose Open Type Def.  It should take you to a Control named "Control 1" (very imaginative ...).
  5. Make any changes (such as giving the Control a better name than Enum, making an Icon for it, writing a Description), and then close the Control.  Choose to Save it, and give it a meaningful name (not My Enum!) and place it in a useful location within your Project.
  6. Now the Enum that you originally dropped on your Front Panel is really an instance of the TypeDef Control.  Try right-clicking on your Front Panel, choose "Select a Control", find your newly-created Enum Typedef, and select it -- you'll get a second copy of your Control.  Try editing the TypeDef to change the name of one of the Enum values (or to add or subtract entries) -- all of your Controls will "adjust" when you save the Enum Typedef.

Bob Schor

Message 4 of 13
(6,055 Views)

@Bob_Schor wrote:
Right-click it, choose Edit, and populate it as best you can.

I find that edit menu a bit of a pain to use, it really slows down my work flow.  Another method of entering items is you can enter text in the Enum wit the text tool, then press Shift Enter, then start typing again to add the next item.

Message 5 of 13
(6,039 Views)

Cool, didn't know that trick!

 

BS

0 Kudos
Message 6 of 13
(6,022 Views)

1. Attached is example template of State machine provided by labview. Enum had two stated "Initialize" & "stop";

2. Here enum constant are placed on block diagram rather than on front panel. How to call it here?

3. Also attached is state_machine control (typedef) , when I edit the name of state from "Initialize" to "Initail" , it got automatically updated in block diagram enums & case structure enum also. How to do that?

4. However when i had added third stage "f", it got updated in enum controls on block diagram but not on case structure.

 

Download All
0 Kudos
Message 7 of 13
(5,988 Views)

I find that edit menu a bit of a pain to use, it really slows down my work flow. Another method of entering items is you can enter text in the Enum wit the text tool, then press Shift Enter, then start typing again to add the next item.

 

The Create Enum From String Right-Click Framework from JKI is also very useful to create enums without the editor.

 

  1. Type the entries of the enum in a string constant.
  2. Convert the string constant to an enum constant with the RCF.
  3. Create a control from the enum constant.
0 Kudos
Message 8 of 13
(5,969 Views)

It actually did get implemented in the Case Structure.  You included the new Enum value by having a "Default" entry as a Case Element, which "catches" anything not already mentioned.  A very useful thing to do for Case Statements controlled by Enums is to remove the Default Case.  Now, if you add a new Enum element, you will get a "broken arrow" because you have a Case Structure missing one of its selectors.

 

You can now use a nice Feature of LabVIEW to help you "fill in the missing Cases".  If there is a Case that is almost the same as the missing Case, find it, right-click and choose Duplicate.  It will copy the code and add the "missing" Case selector for you.

 

Another thing you can do is to right-click the Case and choose Add Case for Every Value.  This will create empty Cases for everything that is missing.

 

You can combine these Features in several useful ways.  Suppose you have an Enum with 30 values, only 5 of which need code (and the rest are "Ignore for now").  Drop a Case Structure, wire the Enum in to the Selector, and choose "Add Case for Every Value".  Find the 5 Cases that need code and add in the code.  Now right-click and choose "Remove Empty Cases".  This, of course, creates a Broken Arrow.  Finally, add a Default Case (to catch the "missing" Cases) and wire the Error Line (you are using the Error Line, aren't you?) through it.

 

Bob Schor

0 Kudos
Message 9 of 13
(5,948 Views)
Solution
Accepted by Vindhyachal.Takniki

I have found the way. Stupid mistake I think on function palette->Select a VI option is for VI only, not for control or libs.

1. On front panel-> control->place a enum

2. Right click enum & make it typedef.

3. Right click again and open tyepdef.

4. Now edit it & add values to it.

5. Save & close it as ctrl extension. \

6. On block diagram->functions->select a VI.

7. Place the enum.

Message 10 of 13
(5,892 Views)