LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I Start, Pause, Continue data acquisition using Producer/Consumer and Events?

I am working on a program to acquire data and would like to have an Event structure for the User Interface and a State structure for data acquisition with the interface between the two structures being a queue.  I can Start and Stop the data acquisition using Events, but have not figured out how to Start, Pause, then Continue (restart) the data acquisition.  It seems that, once I stop, I can't start again.  Does anyone have a simple example of doing this?
 
Thanks.
 
ken
KMoller
0 Kudos
Message 1 of 10
(5,938 Views)
What do you mean by you can't start again?  Are you getting any error messages?
 
Perhaps you can post your VI for others to look at.
0 Kudos
Message 2 of 10
(5,915 Views)
your data aquisition setup is in the state machine. this being in a while loop, there should be no problem to send via queue, the value for the next state from the event structure loop.
Loop 1: event structure - pause button, start button, restart...
Loop 2: case structure - start include initialisation of DAQmx, start, pause, stop...
 
notes:
1) be carfull to have no data dependancy between the 2 loops - no wires, no locals, only the queue / notifier.
2) in order to aquisition to continue: the aquisition is performed in a loop, inside the case structure. then use a stop/pause button to stop the loop and allow for the other cases to perform (less good option), or use a notifier from the event structure (better solution). any event should send, on top of the queued enum value, a notification to stop this inner loop.
3) to stop the two external loops, you will need also to send it from the user event loop. dont forget to add this case in the case structure.
4) in case of hardware error, you might decide to kill the user event loop as well - you will need then a notifier from the case structure to the event structure.
5) you might want an automatic save to file every aquisition run. to do so, send an enum trough the case structure.
 
to start you will find a nice template: vi from template -> design patterns ->producer consumer design pattern.
 
about pause in DAQmx: there is no such function. what you can do is stop the aquisition task, then when you want, start it again, without reinitialising. that means, at start of your program you need to initialise and create your task. however, if you have started, then stopped the task, you can still use the task and start it again.
 
to get an example about data aquisition, you can follow the examples->hardware input and output ->Cont Acq&Graph Voltage-Ext Clk-Dig Start.vi
 
final note: personally i think you can avoid a lot of the above mentionned complications if your system doesnt require too elaborate control, by using a single loop with event structure in it, that includes the DAQ tasks.
see examples->hardware input and output -> events -> ack&graph voltage-int Clk-everyN &doneEvent.ci 
 
good luck.
 
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 3 of 10
(5,894 Views)
If I understand your problem correctly, you actually need to combine a few of the examples from the example finder.  Say you are trying to perform analog input running off a sample clock.  The sample clock can't be "paused" so this is impossible when using the sample clock.  However, you can use another example that uses a counter to generate a pulse train.  A pulse train can be paused.  You can then route the counter output to the Sample Clock.vi input using the ctr0InternalOutput line.  The attached code shows how the two examples work together.

The tricky part is providing the trigger.  The code in the current configuration requires a digital input trigger, most likely off of a PFI line.  If you will be pausing at high frequencies, you will just have to create a digital output task and route that digital output back into the PFI input.  If you are triggering at lower frequences and/or hardware timing isn't essential, you can just start and stop the counter output task whenever you want to.  If you do this, the counter doesn't need to be retriggerable. 

Thats a lot of information - let me know if it all makes sense.

Message Edited by Brian R on 09-17-2007 11:20 AM

0 Kudos
Message 4 of 10
(5,848 Views)
Thank you, everyone, for your help.
 
I tried a few things and hit upon using a Shared Variable between the Event loop and the Data Acquisition loop -- seemed to work fine.  I have attached the simple test case I used before actually implementing it with a CompactDAQ system. 
 
My new question -- will I run into complications by using the Shared Variable in this way?
 
Thanks again.
 
Ken
KMoller
0 Kudos
Message 5 of 10
(5,807 Views)
Your basic structure for the producer and consumer loop looks fine.
 
I am confused a little bit about the shared variable.  It says it is a shared variable, but the SharedVarLib1_StartSTop.vi  file you have attached looks a little more like a global variable while you also have a shared variable library .lvlib attached.  I don't know if its related to the files being individual and not wrapped up in a project file, or if it some difference between how LV 8.5 handles shared variables versus earlier versions of LV that had shared variables.
 
You can certainly communicate between loops using a shared variable or even a global variable.  Though I would use shared variable approach only if you need to communicate between different VI's, especially if they are on different PC's or on real-time targets.  For communication within a single VI such as this just to communicate a start stop to an parallel loop, I would probably just use a local variable.

Message Edited by Ravens Fan on 09-19-2007 04:36 PM

0 Kudos
Message 6 of 10
(5,798 Views)

too bad i dont have LV 8.5 yet (on 8.2 still)

in general, i am not too fond of locals in data aquisition setups, as i do not know when was released the data. a shared variable is preferable, as it has a time stamp with it. or, i use notifiers. i love those ones!

 

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 7 of 10
(5,788 Views)
Thanks Ravens Fan & Gabi1,
 
I tried using a Notifier but found that my data acquisition loop kept waiting for the Notifier to come its way.  Since I had a Event structure doing the Notifier Send, I got confused on how to keep the data acq loop running and only stop when the Notifier went True.  I haven't used Notifiers before, so am pretty sure I am a victim of the Newby User syndrome.
 
As far as the Global VI thing, I just sent the files that were in the folder with the project.  Looks to me like the SharedVarLib1_StartStop.vi was created when I created the Shared Variable.
 
I think I will keep on truckin' with the Shared Variable method, unless there is some glaring problem with it.
 
Thanks again for all of your help. 
KMoller
0 Kudos
Message 8 of 10
(5,782 Views)
well, if you dont see a problem, probably there's not! as long as it does the tric, the how is less important.
about the notifier: you can use a get notifier, instead of "wait on notifier". that means the loop will not wait, rather check if there is one. if not, the value sent will be the default one, in your boolean case a false. should fit what you need.
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 9 of 10
(5,771 Views)

Thanks Gabi1,

The Get Notifier worked great!!  Don't know why I didn't see it before -- guess I just got fixated on the Wait on Notifier function.

Ken

KMoller
0 Kudos
Message 10 of 10
(5,768 Views)