05-21-2015 03:28 AM
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.
Solved! Go to Solution.
05-21-2015 03:34 AM
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.
05-21-2015 07:38 AM - edited 05-21-2015 07:39 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
05-21-2015 07:48 AM
You have discovered the Need for Typedefs (as the previous responder noted). Here's my procedure whenever I create an Enum:
Bob Schor
05-21-2015 08:03 AM
@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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
05-21-2015 10:32 AM
Cool, didn't know that trick!
BS
05-22-2015 01:53 AM
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.
05-22-2015 05:00 AM - edited 05-22-2015 05:11 AM
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.
05-22-2015 07:35 AM
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
05-25-2015 03:25 AM
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.