LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Abort Execution vs Stop Button

Solved!
Go to solution

Hello everyone,

 

I am new to using Labview (2018 version 64 bit) and I was wondering if anyone can give me some advice for a problem that I have been having. 

 

I have been working with a spectrometer in my lab and am currently coding a VI that adjusts the properties of the spectrometer. It is an old spectrometer and I communicate with it via a serial port (Here is the machine's description MS257-S-MC-D 1/4m Imaging Spectrograph (newport.com)). I would like the program to read back to me the current grating that the spectrometer is using when I first run the code, but Labview only shows me the correct information if I press the "ABORT EXECUTION" button on the toolbar while the code is running and then run the code again. If I try to press the STOP button that I have built into my while loop and then run the code again, the program will give me no reading for the current grating. 

 

What are the differences between the Abort Execution button and a while loop's stop button? I know that you are not supposed to press the Abort Execution button when running the code normally, but functionally, what does it do differently than the stop button?

 

Here is my block diagram:

 

Spectra.PNG

 

Thank you all in advance!

0 Kudos
Message 1 of 8
(8,181 Views)

The stop button stops the program by applying the brakes and shutting off the engine.  The abort button stops the program by crashing into a tree.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 8
(8,149 Views)

No one can debug a picture.  Post your VI.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 8
(8,148 Views)

Here is the VI:

0 Kudos
Message 4 of 8
(8,032 Views)

Your car analogy is not helpful, please explain what these two functions do differently in terms of programming and functionality.

0 Kudos
Message 5 of 8
(8,031 Views)
Solution
Accepted by topic author Spectrometer

Actually it is very helpful and often used on the forums.

 

When you use the stop button, you allow the program to do things like nicely close serial ports, references, other things.  Put controls into a safe state if you were interacting with real hardware.  That would be like slowing down a car, parking, stopping and shutting off the engine.

 

The abort button is instant and uncontrolled.  You don't give your program any chance to clean things up nicely.  That is why it is like crashing your car into a tree to stop it.

 

The problem with your code is that you only do a VISA Read one time, right after you program starts.  That VISA Read belongs in the while loop if you want to read the serial port.  Do each of those commands return a response?  If so, you should be doing a VISA Read after every VISA Write.

 

The reason you think your code works with you hit the abort button is that you are taking advantage of the crash and it leaves the engine running.  Thus the VISA Close never occurs.  The port is still open with data in the buffer when you get back in the car again.  A proper shutdown of the engine will execute the VISA close and delete the data in the buffer.

 

Basically you should be periodically reading the speedometer while you are driving the car, and not after you crash it.

Message 6 of 8
(8,027 Views)

@Spectrometer wrote:

Your car analogy is not helpful, please explain what these two functions do differently in terms of programming and functionality.


The car analogy is a good analogy, but this one might be better.

 

You are riding in a car traveling 60 MPH down the road and yell STOP!

 

Stop button:

  1. The driver applies the brakes
  2. Allows the car to come to a complete stop
  3. Puts in in park
  4. Turns off the engine
  5. Removes the keys
  6. Driver gets out

Abort Execution:

  1. The driver just opens the door and jumps out at 60MPH...

What car would you rather be riding in?

 

Granted in your little application it may not make a huge difference, but you are leaving VISA session open. Unless you have "Automatically close VISA sessions" enabled, it's possible that this could leave the serial port unavailable to any other application.

 

In my applications...

 

Pressing the "Stop button" sends my program to a shutdown sequence disconnecting power to the UUT and leaves it in a safe state for the end user.

 

Hitting the "Abort Execution" aborts the program... Nothing else... So the UUT is still powered! 

 

I ALWAYS HIDE the tool bar and run/abort buttons in my executables. The program should start when launched and exit when the "Exit" button is pressed or panel closed. 

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 8
(7,940 Views)

Thank you for your explanation, I put the command in a for loop and it worked like a charm! Keep up the amazing work!

Message 8 of 8
(7,910 Views)