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: 

stop "whlie loop" while inside "stacked sequence structure"

Hi!

I have some questions that maybe someone here can answer.

I have a vi that has this structure more or less:



First, I have this "START/STOP" button that works like this:

1. When I click it for the first time, he goes down and stays down and the process inside the "select case structure" begins.
2. When I click it again (to make it off) I want to stop the two "while loops" NOT WAITING for the "Stacked Sequence Structure" to end!!!!

Basically, this is my problem. I don't know how to "get out" of the stacke sequence.

Another thing... This method to use in the START/STOP button can be replaced by something more adequated?



Thanks in advance.

zephirus
0 Kudos
Message 1 of 8
(4,755 Views)
You cannot do it the way you want with the way that you have the structure set up. I would suggest a state machine type of structure. You will always advance to the next frame in a sequence structure you cannot prematurely stop a sequence structure.



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 2 of 8
(4,750 Views)
Ok. So, what you're suggesting is that I compare the value of the start/stop button everytime I change frame in the sequence structure??? Or is something else? Can you suggest another way to do this?

Thanks
0 Kudos
Message 3 of 8
(4,744 Views)

Ahhh, the stacked sequence structure... You cannot escape it!

Maybe you should take two steps back and look at your code layout. Look at some code examples, especiallly state machines. Now redesign from scratch.

Stacking many layers of loops and sequence structures like one of those russian doll sets is simply bad form. I am sure there are better ways. What exactly are you trying to do?

0 Kudos
Message 4 of 8
(4,741 Views)
I have to control an UV Spectrometer. Basically it's like this:

I have 5 controls:

two voltages, Vi and Vf
a voltage increment step, vstep
a step time, tinterval
and a scan number variable, nscan

When I click the START/STOP button, it will begin the process:

1. It sends Vi to the spectrometer, then increments Vi by vstep and then it compares with Vf (if it's greater than Vf, then it ends the inner loop)

2. when the first while loop ends (corresponds to the first scan), the program executes the second frame of the big sequence structure. At the beginning of the program I have "scan=1". This second frame adds 1 to this value. In the third frame, it compares the scan with the nscan number (if it's greater, it ends the while loop).

The the START/STOP buton would go to its initial state (off)

END OF PROCESS

I made this with the sequence structure cause it's at first glance more easy not to lost ourselves, but....


So, if someone can help....
0 Kudos
Message 5 of 8
(4,734 Views)

You cannot break out of a sequence structure. here's how a sequence structure works.

Let's say you have while loop 1 and inside WH1 you have a sequnce str. with 3 cases. while loop 1 will proceed like this.

1. check stop condition.

2. execute case 1.

3. execute case 2

4. execute case 3.

5. sequence str ends

6. while loop checks stop condition and continues back at step one.

what you need is a type of stucture that will work like this.

1. check stop condition.

2. execute case 1.

3. check stop condition.

4. execute case 2.

5. check stop condition.

6. execute case 3.

7. check stop condition and if not met repeat steps 1-6.

This type of architecture is called a state machine. i would do some research on the forum on in the LV examples on the state machine. Your code as it is, is at a dead end. It will not do what you want and if you do somehow cludge it together to get it to work you will most likely never be able to maintain it or upgrade it. Take altenbachs suggestion and re-think what you actually want the code to do.




Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 6 of 8
(4,730 Views)
attach a copy of your code and I will see how I can help further.



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 7 of 8
(4,719 Views)
0 Kudos
Message 8 of 8
(4,709 Views)