LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State machine with event structure

Here is a simple example of what I am currently doing with some of my vis.  It works fine, but as I am learning it probably isn't the most elegant way.  The state machine is used to wait and handle user inputs from the button, the event structure is only there to handle the Panel Close event, because that is the only way I know how to do that.  I don't like the fact that I have to use the timeout case of the event structure to keep the state machine going.  Is there a better way to do this?  Thanks

0 Kudos
Message 1 of 14
(4,019 Views)

For what you are doing, you might as well just eliminate the event structure.  Your VI would functionally virtually the same.

0 Kudos
Message 2 of 14
(4,001 Views)

Why do you need the panel close event, currently there is no code in the case. If you want to ignore the panel close button, just uncheck "allow user to close panel" in the VI configuration.

 

So far, all state execute linearly and once you are at the stop, there is nothing else you can do, I assume there is more to it. Isn't there a way for the user to influence the states somehow? Currently, a state machine seems overkill.

 

Instead of the 125ms wait, you could just set the event timeout to 125ms and delete the wait.

 

All your force# cases are identical. You probably could combine them into one and proceed to the next state if the array size is 3.

You don't need all the diagram constants for the "current case", just wire across from the case terminal. Right?

Message 3 of 14
(4,000 Views)

Those are some good ideas, thanks.  If I get rid of the event structure how do I handle the panel close event if the user wants to close the window by pressing the red X on the top right?

0 Kudos
Message 4 of 14
(3,959 Views)

@secr1973 wrote:

Those are some good ideas, thanks.  If I get rid of the event structure how do I handle the panel close event if the user wants to close the window by pressing the red X on the top right?


Go back and read the very first line in Altenbach's reply.  Well maybe you don't know where VI Configuration is located.  Click on File - VI Properties.  Then select Window Appearance in the selection box.  Then click the Customize button.  Uncheck the box next to "Allow user to close window".  Click OK and OK and save the vi.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 14
(3,952 Views)

Ok, I think I am confused.  I was under the impression that you have to use the Panel Close event in order for the user to be able to close the window.

0 Kudos
Message 6 of 14
(3,938 Views)
No, the panel will just close. No code needed. Try it!
0 Kudos
Message 7 of 14
(3,923 Views)

So I tried it out and sure it closes the window but it doesn't stop the vi from running, it just locks up my main program. I just looked back at my example and realized that I didn't add anything into the panel close event, my bad.  This is the updated version.

0 Kudos
Message 8 of 14
(3,900 Views)

You might want to stop the loop from the Stop case as well as the event cases.  Wire a True constant from the stop case to an OR gate with the other OR input from the Event cases so that either one stops the loop.  Currently, if you run the VI and press Record Force 3 times, the VI continues running for nothing.  Pressing Record Force more than 3 times does nothing.  It would be better to stop the program after the third record, which goes to the stop case.

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 14
(3,889 Views)

OK, now you are discarding the panel close event. As I said, you might just configure the VI to ignore the close button instead. No event needed.

0 Kudos
Message 10 of 14
(3,872 Views)