From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Handling a state machine using a single button

Solved!
Go to solution

This should get you pretty far down the road.

 

Example.png

Tim
GHSP
0 Kudos
Message 11 of 23
(1,089 Views)
Solution
Accepted by topic author nikvl

OK this one is actually closer to what I think you are looking for. Change the timing on the timeout of the event structure to execute the loop faster.

 

Example.png

Tim
GHSP
Message 12 of 23
(1,083 Views)

I found an example of a Event State Machine by Bob Schor and tried modifying it, but I ran into the problem when I click OK, it goes straight into the timeout rather than generating an event.

 

Right now most examples contain a pause or idle state but I don't want the program to be idle when I press OK after the Run is clicked.

 

My aim is to:

 

1) In the Init state, some things are initialized and then it goes to idle state and wait for user button press

 

2) User press Run to start the state machine (This button should only be done the first time)

 

3) User press OK and next state to Process 1 should be triggered WITHOUT pausing (The timeout for Process 1 should be same as Run but if I make a timeout case for Process 1 (which is identical to Run anyway) I'm uncertain of how to wire the same OK button to stop that loop

 

4) I didn't create more entries but if User clicks OK again it should go to process 2 and so on (until it reaches a certain Process X and the Finish event is triggered automatically or manually at any point)

 

p/s: please ignore the 'default if unwired' cases, everything will be wired in the real program

0 Kudos
Message 13 of 23
(1,055 Views)

Did you look at the second example I gave you? It does not stay idle. Take a look. If you need the loop to go faster just change the time on the time out loop to make it go faster.

Tim
GHSP
0 Kudos
Message 14 of 23
(1,048 Views)

Hi Tim,

thank you for the example but it did not work when I pressed any of the buttons (except Exit). I think it might be stuck at the timeout case too. The 'Next' button didn't generate an event to update the Current process. I think the Case structure should be inside the event structure, no?

0 Kudos
Message 15 of 23
(1,042 Views)

You need to hit start. That loads the states into the array and starts the process. Next make it go to the next step. Stop stops the process. Exit will exit the program.

Tim
GHSP
0 Kudos
Message 16 of 23
(1,035 Views)

Yes I did that and tried with different timing. Current step shows 'none' while current process remain blank no matter if I press start or next.

0 Kudos
Message 17 of 23
(1,030 Views)

Did you add states to the array on the front panel?

Tim
GHSP
0 Kudos
Message 18 of 23
(1,026 Views)

Yes, so then the start works, and then nothing else, not even the exit anymore. Because the it goes to the next state in the case selector and there's no event case to detect any other button press. 

0 Kudos
Message 19 of 23
(1,018 Views)

I fixed that on the second example v

Tim
GHSP
0 Kudos
Message 20 of 23
(1,015 Views)