Wednesday, August 18, 2010

Exercise 7 - Simple State Machine

Create a VI using state machine architecture that simulates a simple test sequence. The VI will have an initial state, where it will display a pop-up message indicating that it is starting the test.  Then it will proceed to the next case and then to the final state where it will ask the user whether to start over or end the test.

Front Panel
Rather than start from scratch, we will use a VI template to create our state machine.

1.      From the initial LabVIEW screen click on New…, and choose Standard State Machine, which is located under the VI from Template » Frameworks » Design Patterns heading.
2.      Examine the template, and then save it in another directory before you begin working on it.


Block Diagram

1.      Right click on the enum constant labeled Next State and select Open Type Def.
2.      On the front panel of the StateMachinesStates.ctl Type Def VI, right click on the States enum control and choose Edit Items.
3.      Add two more states.  Call them “State 1” and “State 2”
1.      Close the State Machines.ctl Type Def Front panel and save the control with the default name when prompted.
2.      Right click on the Case Selector Label of the case structure and choose Duplicate case.  Do this one additional time so that there are four cases: Initialize, State 1, State 2, and Stop.
1.      Change the value connected to the Wait function to 2000.
1.      Right click on the shift register on the left side of the while loop and create an indicator.  Change it’s name to “Current State”.
2.      In the “Initialize”, Default case place a One Button Dialog function and wire a string constant into the Message input.  Type “Now beginning test…” into the string constant.
1.      Change the enum constant labled Next State to “State 1”.
2.      Change to the next state in the case structure (“State 1”) and change the enum constant labled Next State to “State 2”.
3.      Change to the next state (“State2”) and add the following code.
a.       Place a Select function and connect two enum constants
(Tip:  Copy the enum constants from one of the previous cases)
Place a Two Button Dialog and wire create the constants as illustrated below.
14.      Run the VI.
15.      Save and close the VI.

End of Exercise



No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Popular Projects

My Blog List

Give support

Give support
Encourage Me through Comments & Followers

Followers