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: 

cannot stop while loop

Solved!
Go to solution

 

Hello,

 

I want to count how many times the Boolean state has changed. But somehow the stop button cannot abort the statement.

 

0 Kudos
Message 1 of 8
(3,150 Views)

Study up on dataflow.

You're always going to be waiting in your inner while loops with this structure.

 

Look into Event Structures or using a Shift Register to track value changes.

 

Your polling while loops inside of another while loop will not work for your intended purpose.

0 Kudos
Message 2 of 8
(3,144 Views)
Solution
Accepted by topic author 416E64

Your code is way too constipated. Here's one simple solution.

 

 

Download All
Message 3 of 8
(3,138 Views)

 

 Smiley Tongue thx~

0 Kudos
Message 4 of 8
(3,125 Views)

@altenbach wrote:

Your code is way too constipated. Here's one simple solution.

 


 

Wiping coffee off my monitor now....

Sometimes you just know when someone's Freudian Slip is showing.Smiley Surprised


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 8
(3,111 Views)

No slip. thats exactly what I meant.

 

(the stop will work after switching the boolean a few times, it's just a constipation issue. Impaired dataflow) 😄

0 Kudos
Message 6 of 8
(3,104 Views)

 

in the new attached file where i added "read digital input", 

how to use one single stop button to abort the whole program with two loops,

and how to set the default port as "port 1" but not "port 0"?

 

0 Kudos
Message 7 of 8
(3,083 Views)

All you need is a single loop (and stop button). Just place the code from the lower loop inside the upper loop.

 

Your current code is not stable because the lower loop might miss an update (race conditions!). What determines the loop rate of the upper loop? Is there some hardware timing or does the loop need a small wait?

 

You could even monitor multiple lines by tapping into the boolean array and maintaining an array of numeric in the shift register. The rest of the code basically stays the same.

0 Kudos
Message 8 of 8
(3,077 Views)