Next all the programmer has to do is add tasks to each case individually. After the work is finished, a new value can be saved on the shift register to be used at the start of the loop next time. For example, a shift register will start with information that will be worked on in the loop. A shift register is used to pass information around in a while loop. A state machine also relies heavily on shift registers. Doing this makes programming a lot easier for the user to understand because instead of looking at number codes they are looking at a few words describing what is going on. An enumerated constant is a constant word or phrase is changed to a simple integer from 0 to n − 1, where n is the number of cases the user would like to have. The while loop can have a special constant wired to it, called an enumerated constant. In LabVIEW state machines can be started by simply creating a while loop with a case structure located within the loop. To help explain this feature, we will use a simple vending machine program to help illustrate the technique.Ĭommon devices of a state machine Ī simple while loop located in a while loop using enumerated constants and shift registers A state machine can help the program respond intelligently to different types of data that the user could put in.
In LabVIEW, state machines are even more powerful. The action is how the program will react to the particular event that has occurred. An event for this program could be the money being inserted or the person hitting the start button. The example that we will be building is a vending machine that dispenses an item after the user has inserted the correct amount of money. Events are occurrences that have specific meaning to the program itself.
Developing these wisely will help to make the state machine run more efficiently. States work to help break up the big picture and help to make everything run smoother. For example, a state could be waiting for the user to do something, or running a calculation. The state is the position or status that the program is at when it is working through the problem. State machines revolve around 3 concepts: the state, the event, and the action.