LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine..switching state with a button

Currently , if I change the state ( in enum in my block diagram) then press the correct button, my code works. Otherwise it won't..for example:

choose Initialize in the code, then run the code, enter a number then press initialize ..it works..but if you press Run it won't work unless you stop the program , change the state to Run,press Run..What to do?

0 Kudos
Message 1 of 3
(3,786 Views)

You need a transition state in each one of your states.  

 

A state machine 'state' always has 2 parts: State code, which is what you've got in your initialization state, and transition code, what changes the enum to the run state.  If you want to do that you'll need to add a switch to run in the enum wire.  Looks like the attached.  Add transition code for each one of your states and your problem should be fixed.

 

Cheers,

 

Tim

0 Kudos
Message 2 of 3
(3,777 Views)

Hi Canucks,

 

Every time you run a state you just pass through the previous state, so it is always going to keep calling the same state over and over. What you want to do, is output the next state that should be executed. For example, in the "Initialize" state you want to output whatever state should be run next, so you can drop a constant rather than wiring through. While you're at it, it's best to make your enum a typedef (a control file that defines the datatype), then use the typedef everywhere (it will have the black triangle on the corner). That way, if you want to add states, you just add it to your typedef and it will update everywhere.

 

temp.PNG

Message 3 of 3
(3,773 Views)