LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

STOP button to safely close program & reset hardware

Solved!
Go to solution

I do not want to have to use the abort execution button, as I hear that is not the correct way of closing out your .vi

 

I would like to program a simple STOP button that when pressed, aborts the VI but also safely resets the hardware (for example, turns off a power supply, resets a drift oven, etc) when it is pressed. Otherwise, it just continues running the program until it is finished.

I know this is a relatively simple problem but I have not been able to figure out a simple way to do it. 
I believe Event Structures are my friend here, but I am a bit unsure how to do this. 

 

Could anyone walk me through? 

 

Thank you ! 

0 Kudos
Message 1 of 10
(3,594 Views)

Post your VI so we know what your architecture looks like.  That will dictate how to handle a stop button.

 

Personally, I avoid using a stop button and instead use the Front Panel:Close? event (the filter event version since I discard the actual closing and later close the panel myself when I am done).  But, again, how you handle this depends on your architecture.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 10
(3,557 Views)

Attached is my .vi. Warning, I was a bit hesitant to upload as it is a bit messy. 

0 Kudos
Message 3 of 10
(3,507 Views)

I cannot see the subVIs as they were not included.

 

As of now your program runs a specified number of loops and then stops.

 

If you want to keep this architecture, \emph{if}, then your options are

  1. Put all your close operations after the loops are finished and shut down properly.
  2. If you need to stop in the middle of your loop, then you need to add a conditional stop to your for loops. This will stop the loops, and then you go into your shut procedure. However, the shutdown may not be immediate as it depends on what is going on in your subVIs.

Hints: Look at state machines. If possible download the JKI State machine form VI package manager and learn to use it. Your program can probably be rewritten in one loop.

 

cheers,

mcduff

0 Kudos
Message 4 of 10
(3,493 Views)

My apologies, attached is the .vi with sub-VI as well.

Also, do you have a link to this state machine you are referring to that I can use as a basis?

Thank you. 

 

Download All
0 Kudos
Message 5 of 10
(3,489 Views)

What version of LabVIEW do you have?

 

Recent versions have come  with VI Package Manager, open that program and you can find links to the JKI State machine. It will install it correctly if you use VI Package Manger. Otherwise you will have to do a manual install from https://github.com/JKISoftware/JKI-State-Machine

 

mcduff

0 Kudos
Message 6 of 10
(3,482 Views)

I am using LabVIEW 2009. 

0 Kudos
Message 7 of 10
(3,480 Views)

Bits and pieces of the new subVIs were missing. I suggest you look at the tutorials and examples for inspiration.

 

Another piece of advice, it looks like you are constantly initializing and closing VISA resources. Initialize them once before the loop, keep them open while in the loop, and close when the loop is finished.

 

VI Package Manger is here https://vipm.jki.net/

Not sure if it works with LabVIEW 2009.

 

Look at the state machine examples that ship with LabVIEW.

 

mcduff

0 Kudos
Message 8 of 10
(3,478 Views)
Solution
Accepted by topic author eleal1893

I had a look at your VI. The main thing you need to fix if you want to be able to stop at any time is that you are using the Time Delay ExpressVI in between your temperature reads. Your code will be stuck there waiting and nothing else will execute until the 5 seconds (or however much) is up, and this means that you won't be able to stop at any time since the code will not read your stop button until it is done with the delay. What you need to do instead is use an architecture where you check what time it is or whether stop button is pressed - if the time is up, go to the next thing - if stop button is pressed, stop- otherwise, go back and check again.

 

Try implementing a state machine architecture. Here, I made an example for you of how you could start changing your VI into a state machine. It is just a basic outline. See if you can understand it, and let me know if you have questions, and then try putting your code in.

Message 9 of 10
(3,475 Views)

I see. I will give this a shot, and post questions if they come up

Thank you for your replies!

0 Kudos
Message 10 of 10
(3,472 Views)