LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop button

Solved!
Go to solution

Hi,

I would like my stop button to essentially "jump" out of 2 loops and execute the code at the end. I tried a case structure but this only worked to exit one for loop and not both of them.

 

Additionally, i also read theres a way to run program on startup instead of pressing the run button, how is this done?

 

Thanks 

0 Kudos
Message 1 of 7
(3,405 Views)
Solution
Accepted by topic author newman3108

Enable the conditional terminal on the for loop and check if the button is pressed and exit if it is. 

 

 

Certified LabVIEW Architect
Message 2 of 7
(3,396 Views)
Solution
Accepted by topic author newman3108

So are you looking to end your loop early?  If that is the case, then you can right-click on your FOR loop and then enable the Conditional Terminal.

 


@newman3108 wrote:

Additionally, i also read theres a way to run program on startup instead of pressing the run button, how is this done?


Build an executable.


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 3 of 7
(3,395 Views)

@newman3108 wrote:

Additionally, i also read theres a way to run program on startup instead of pressing the run button, how is this done?


While building an executable is the preferred way (but you need the app builder for that!), there is also a vi option to "run when opened".  (This works when opening from windows explorer, but not from within a project)

Message 4 of 7
(3,352 Views)

A few generic comments for your VI:

  • If you want the elements in order, you don't need to wire the indices of "index array". Saves lots of time and avoids mistakes! (See also)
  • If you "bundle" into a cluster for the chart instead of building a 1D array, you don't need the conversion to 2D array.
  • If you use the correct mechanical action for the "start button", you would not need the value property.
  • There is never any need for greedy loops.
  • I would recommend a state machine architecture instead. Currently it's a one-shot deal, burning 100% of a CPU core waiting, then rolling down the hill until finished. Seems boring 😉
  • There actually is a +1 primitive.
  • ...
0 Kudos
Message 5 of 7
(3,348 Views)

Thanks for your reply,

  1. Got rid of the indices 
  2. Im going to leave it as an array because im now writing it to excel 
  3. Is switch when pressed not the correct action?
  4. Ive just read your greedy loops bit, is the solution to just as a wait in?
  5. I agree, dont think im at that stage yet tho, just trying to get it working first 😉
  6. What about +1?

Cheers

0 Kudos
Message 6 of 7
(3,324 Views)

@newman3108 wrote:
3. Is switch when pressed not the correct action?

Typically the correct action is "latch when released". This way the button is normally OFF and when pressed will remain TRUE until is is read by the code, at which time it will automatically return to FALSE. (No way for the code to miss it as e.g. with "switch until released" and no need to reset it as e.g. with "switch when pressed")

 


@newman3108 wrote:

4. Ive just read your greedy loops bit, is the solution to just as a wait in?


Yes, that's the "bandaid" solution. A proper state machine is preferred. A greedy loop spins many millions of times per second, consuming 100% of a CPU core, draining your battery, stressing the thermal management of the CPU, and starving all other processes running. Even a 1ms wait would reduce the CPU use to a tiny fraction of a %. Typically you make it longer, e.g. 50ms.

 


@newman3108 wrote:

6. What about +1?


increment.png

 

Message 7 of 7
(3,300 Views)