LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

terminate loop and get data

Solved!
Go to solution

I need to acquire the DAQ values every x seconds. The wait in the DAQ loop is set so that next N samples are acquired after x seconds. When the stop is pressed the DAQ consumer loop stops after the x sec that is wired to Wait function.

1. How to stop the inner loop immediately when a stop is pressed?

 

Also need to write the acquired samples after doing some math on the samples.

1. Plan to queue sample to pass to file consumer loop. Is there any other recomendation such that file loop does not miss any samples? How much of data can a queue hold?

 

Thanks.

0 Kudos
Message 1 of 10
(2,752 Views)

Use 'stop all' local variable & with OR condition give it to outer while loop also.

 

It will be great if your post your code with 2011 compatibility.

 

Thanks

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 2 of 10
(2,711 Views)

Ranjeet,

 

That will not work. The local variable in the inner loop is probably read as soon as the iteration starts. Any changes will not have any effects until the next iteration.

 

sonotk,

 

We cannot tell from your image but I am presuming that the value wired to the circled Wait (ms) function is 1000*x.  If you need rapid termination response, it is better to make the wait much shorter. For example if the desired time between acquisitions is 1000*x, make the wait 100 ms. Keep a counter and when the count value exceed 10*x, then do an acquisition and reset the counter. With such a method your system will respond to a stop command in no more than 100 ms.

 

Lynn

0 Kudos
Message 3 of 10
(2,699 Views)

Hi 

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 4 of 10
(2,690 Views)

No! The outer loop will always "read" the value.

 

This is basic dataflow, the fundamental paradigm of LabVIEW. Any node can begin execution only when data is available at all its inputs and it will complete execution after all nodes internal to it have completed their execution.

 

In the case of the code image posted in this thread the inner loop will not complete one iteration until all the code inside has finished.  Let's assume that the Is List Empty subVI executes in 1 ms and the DAQ Actions subVI takes 100 ms. Let the value coming in to the Wait ms be 1000 ms. The the loop starts its iteration: The Wait starts. The Stop All local is read. The Is List Empty subVI starts. One ms later Is List Empty ends and DAQ Actions starts.The OR gate has both its inputs and executes, generating the value which will stop the loop or allow it to continue. One hundred ms later (~101 ms after starting the iteration) DAQ Actions ends. The new values are placed on the indicators. After 1000 ms the Wait ends and the iteration ends. If the OR gate output was False a new iteration begins immediately. If it was True, the loop stops, the rest of the code in the case executes and then the outer loop completes its iteration. For this case the outer loop will always do at least one more iteration because a default value is wired to the stop terminal. The outer loop will only take nanoseconds or microseconds to get to the next case.  But the outer loop DOES read the value of the boolean coming from the case structure (always False in this case) to determine whether to continue or to stop.

 

Lynn

0 Kudos
Message 5 of 10
(2,686 Views)

Hi 

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 6 of 10
(2,682 Views)

No, the outer loop will read the value of the Stop local variable as soon as the iteration starts. There is no data dependency (data input) to the Stop local variable therefore it will execute immediately. So if the stop is set while in the inner loop the outer loop will execute one more iteration. You need to force the read of the stop button to ovvur after the case statement has completed.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 10
(2,665 Views)

Hello Lynn,

 

The input to wait function is 5secs. It is read from a file. Sample needs to be acquired every 5 secs. How will this be achived with a counter? The counter will have to count till 5000 and the stop response will be slow, or am I missing the point?

0 Kudos
Message 8 of 10
(2,648 Views)
Solution
Accepted by topic author sonotk

sonotk,

 

You missed the point. Rather than having a 5000 millisecond Wait, use a 100 ms Wait and count the number of times you have waited 100 ms.  When the count reaches 50, take a sample and restart the counter. 

 

The counter is just as shift register containing an integer. Inside the while loop you have a case structure. Test the count shift register to see if it is 50. If True, use the True case of the case structure. Inside there is everything in your loop except the Wait and the stop logic. In the false case you add 1 to the shift register and wait 100 ms.

 

In looking at your code image again it appears that the shift regsiters with TempData and VoltData are not needed because you never use the previous iteration data at the left side.

 

 

Ranjeet,

 

Make a simple VI with two loops and some Waits.  Run it with Execution Highlighting turned on to see what happens.  It is a good learning tool.

 

Lynn

Message 9 of 10
(2,643 Views)

Thanks Lynn, that worked.

You are rght I should have removed the shift registesr for volt and temp, these are replaced with queue to send the data to file loop.

thanks again!!

 

0 Kudos
Message 10 of 10
(2,617 Views)