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: 

Problems switching cases

Solved!
Go to solution

Hello,

I have written a simple code to execute test sequences and it works fine except for the scenario when the user wishes to abort the test sequence while in process.  I have tries several different methods to achieve this but have been unsuccessful. 

The desired results when the Abort button is pushed is for the timer to be reset to 0, the progress bar to be reset to 0 and the throttle input to be reset to 0.  Are case structures not the method to use for what I am trying to achieve?  Can anyone suggest a better way to do this?

Attached is the main VI "Hot test" and the subVI "Throttle control"

 

Thank-you

Download All
0 Kudos
Message 1 of 5
(2,163 Views)

I just gave a quick look at your VI. In your cold start test case there is a loop that will execute for 54 seconds. This case can not exit until that is done. If you press the abort button you will have to wait that long.

 

What you need is a state machine architecture. Do a search for examples in this forum. There are many.

 

As for triggering actions when buttons are pressed you should use an event structure if you have the professional version of LabVIEW or above.

 

For a quick solution you can do a comparison in the 54 second loop. Create a local variable for Test Mode and check if it equals "Abort". Wire that and the =0 output to an or gate and connect it's output to the stop. You have another loop above this where you will have to do something similar. I have not looked at your program closely enough to know if there are going to be other issues. Also this is not the best way to program. You can already see the nightmare unfold. But if you need a quick bandaid to get something going this might be ok.

=====================
LabVIEW 2012


0 Kudos
Message 2 of 5
(2,154 Views)

Thanks for the suggestions.

Your suggestion worked for the 54ms timed loop, if you have a suggestion on how to program this better that would be appreciated. 

However my main concern is the other loop which controls the output to the DAQ.  I have tried a bunch of methods using a state machine, event structures, case structures, etc, but I always get hung up on the ability to abort the timed test sequence without  affecting the regualr progression of the timed test sequence when it is not being aborted.

Can anyone point me in the direction of an example that shows a multistage timed sequence that can be exited at any moment of the sequence?

0 Kudos
Message 3 of 5
(2,127 Views)
Solution
Accepted by topic author Juniper

Can you post your attempt at a state machine? Attached is an example of a state machine for your upper loop. It is the file called state machine.vi and is called by state machine demo.vi.

 

Take a look at state machine.vi. The first thing you should notice is that it is a while loop with a true constant wired to stop. That is the loop will execute for one iteration and the VI will exit. If you look through the case structure you will see that there are no wait functions. The VI will run and imediately return but the next time it is called it will know what state to go to. So if someone presses the abort button then the next time the VI is called it will be in the "done" state. That state sets your indicators the way you want and sets the next state to "exit". This way the caller knows that the state machine has completed execution.

 

The thing to keep in mind if you want a state machine to be "abortable" in a short amount of time is to make sure that you have no states that take a long time wherever possible.

 

I suggest that you open the state machine.vi block diagram and turn on highlight execution. Then run the state machine demo.vi. You should be able to figure out what is going on.

 

I used a string for the state. A lot of people will use enums. Make sure that if you use an enum you make it a type def.

=====================
LabVIEW 2012


Download All
Message 4 of 5
(2,112 Views)

Thank-you for the help.  Your example with the "Get Date/Time" and the "wait" cases was exactly what I was needing.  So simple now that I have seen it but something I just couldn't seem to figure out on my own.

0 Kudos
Message 5 of 5
(2,083 Views)