Showing results for 
Search instead for 
Did you mean: 

Help with Switch transition state

Go to solution

Hello gents, 

I am trying to change my sequential program into a state machine logic.

I have two issues that i'm facing right now:

1) How can I put in standby a state until the user (after checking if all the results are correct) clicks a button (Boolean Switch) in the Panel Control and tells the program to go on with the next state?

2) Is it possible to check how many times a state occurs and depending on that, the specific state may perform the same action on a different data? I'll explain better with an example: imagine my program runs through several states (state 1, state 2, state 3, state 4, state 5, state 6), once in state 6 the program has to go back to state 3. The problem is that, if it is the first time doing the state 3 then it uses the data from state 2, otherwise it must use the data coming from stage 6. On top of that if it's not the first time that the program performs state 3 then after that it may skip immediately to stage 6 again.


Hope i explained myself clearly and thanks for all the help!

0 Kudos
Message 1 of 3

Use programming logic available to you!  Perhaps it is another shift register besides the one for the next state, one that tells which set of data to work on.  Keep a shift register of data, perhaps an array of booleans, that keeps track which stages of data have already been handled before.  Then use logic functions to determine whether to move on to state 6 or state 4.

0 Kudos
Message 2 of 3
Accepted by topic author BonifacioLupo

There are a few good NI tutorials on state machines.


There is also simple example in the LabVIEW Example Finder called State Machine


Typically a state machine will initialize first, and then go into a "Wait" or "Idle" state until something triggers the program to the next state.  


To keep track of how many times something happens, create a counter with a shift register.  You can initialize your counter at the start of your program just like the state machine initializes the Case Select value. 


Set your counter to 0 outside the loop, and then create a state called Add Counter or similar that you will trigger when your conditions are met.  


In the Add Counter state, add 1 to the value in the counter shift register and send your state machine back to its monitoring state, or you could have a condition that checks the new value of your counter first before sending it to the next state.  


Patrick Allen:
Message 3 of 3