LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to repeatedly switch between nested while loops?

Hi all,

 

I have a DAQmx task that I would like to be able to start and stop as needed without having to stop the entire VI... Essentially, I want to be able to start/stop the DAQ (to reduce memory load etc) when I need to examine the acquired data and get various values etc... I could simply stop the data going to the chart while I zoom-in and examine the data etc, but it seems inefficient to keep the DAQ reading data in the background for no reason when I do this... I have tried using a single while loop with a case structure to remove/hide the DAQmx read vi, but I get buffer errors as the task is still running and the buffer runs out of memory... 

 

I understand the DAQmx start and stop vis should be placed outside the while loop to improve performance; hence the idea of switching between nested while loops... I have attached my initial attempt using simple loop timers to determine the functionally... However, this is not working as desired...

 

Any suggestions would be much appreciated...

Thanks...   

0 Kudos
Message 1 of 7
(4,525 Views)

Hi all, I have made some changes and now have it working... Note I have multiple parallel loops and the outer loop is stopped via a button in another loop through the queue...

 

Any comments on this are appreciated... Thanks...

0 Kudos
Message 2 of 7
(4,510 Views)

What you posted looks extremely fragile.

A few suggestions:

  1. Initialize your task outside the loop, then start and stop the task inside the loop. When the loop exits clear the task. It should restart fast, not sure what you need.
  2. Process your data in a parallel loop. My guess is that you are processing the data in the same loop as you are acquiring. You should not get a buffer error. I have acquired data at high rates without any issues.
  3. You will need to show more to get better advice.
0 Kudos
Message 3 of 7
(4,490 Views)

I would recommend Using a Queued Message Handler in LabVIEW

  • Use the Start button event to enqueue an Init case. The Init case enqueues a Read case on success.
  • The Read case enqueues another Read case.
  • Use the Start button event to enqueue a Pause case. 
-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 4 of 7
(4,486 Views)

Thanks... I will make the revisions you are suggesting...

 

When you say to initialise the DAQmx Start outside the loop, do you mean outside the inner loop (so the DAQ task will initialise one time only on the first iteration of the inner loop )? Or outside the outer loop (so the DAQ task is initialised once only when the vi first runs)?

0 Kudos
Message 5 of 7
(450 Views)

Thanks... How could a "pause" case to stop the DAQ read be done? Would the DAQ need to be stopped and reinitialised before reading again?  

0 Kudos
Message 6 of 7
(448 Views)

I made a quick mode of an included example before I go to sleep, snippet below and 2021 version attached.

 

  • Do your processing outside the loop, use a queue, channel wire, user event etc.
  • The task won't start until you hit the play button. You can pause/stop it by hitting the stop button. You can restart it by hitting the play button. Once you hit the cancel button, the loop exits.
  • You can add to the event case for logging and other features. This is the initial seeds of a state machine.

snip.png

Message 7 of 7
(442 Views)