How come my Daq Session isnt continous?
0 Comments
Answers (2)
0 Comments
@Michael — the behavior you’re seeing is actually expected with how MATLAB handles background DAQ sessions. When you call `startBackground`, the acquisition and callback (`processData`) do run continuously in the background, but your main function keeps executing right away. Since the very next line after `startBackground` is `stop(daqSession)`, the session ends almost immediately — that’s why it only seems to run when you add a `pause()`.
The `pause(100)` doesn’t really make the DAQ “run for 100 seconds” — it just blocks MATLAB from reaching the `stop()` call for that long, so your background listener keeps firing during that pause. Once the pause finishes, MATLAB executes `stop()`, and everything shuts down.
@Walter Roberson is absolutely right that your `processData` callback isn’t looping by itself and that you’re stopping the session prematurely. The DAQ continues to generate events while MATLAB’s main thread is alive, but once your function ends, it’s all cleaned up.
If you want to run continuously and stop manually, you’ll need something that keeps MATLAB’s event loop active — for example, a small UI window with a “Stop” button or even a `questdlg()` prompt would work. That way, the acquisition continues until you tell it to stop, instead of depending on an arbitrary pause duration.
So in short:
- The DAQ is continuous; it’s your script that’s ending too soon.
- The `pause()` just delays the script from finishing.
- The clean solution is to replace the pause with a user-controlled stop (like a button or dialog).
Hope this helps.
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!