How to close a DAQ session with triggers remaining
10 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm using the DAQ toolbox to send a pattern to a motor whenever an external trigger arrives. For now, I can successfully drive the motor upon trigger arrival. However, since I do not know the exact number of triggers during the recording session (dependent on animal), I set the d.NumDigitalTriggersPerRun to 200 to ensure the motor moves every time theres a trigger.
However, this introduce a problem as I can't manually close the DAQ session, I've tried following without success:
- type stop(d) in command window
- ctrl-c
- Force re-run by clicking run above (matlab will always crash)
My code can be simplified as follows, thanks in advance!
clear; close all
d = daq('ni')
d.NumDigitalTriggersPerRun = 200;
% lines to addinput
% lines to addoutput
addtrigger(d,"Digital","StartTrigger","External",'Galvo/PFI0'); % add trigger
% lines to generate motor pattern
% run session
stop(d); % stop session if required
flush(d);
preload(d,pattern);
start(d);
2 件のコメント
Walter Roberson
2023 年 8 月 15 日
You "clear" so we know that there are no variables remaining in memory -- that in particular there is no d before the assignment you show.
You then have a structure assignment, and pass the structure to addtrigger(). But addtrigger() does not accept struct: it expects DataAcquisition objects.
採用された回答
Ninad
2023 年 8 月 28 日
編集済み: Ninad
2023 年 8 月 31 日
The script may not immediately stop when using ‘stop(d)’ or ‘Ctrl+C’ due to the asynchronous nature of DAQ operations. In an asynchronous session, data acquisition tasks run independently of the main program flow, allowing concurrent execution. MATLAB's DAQ operations default to asynchronous mode, enabling multitasking during acquisition. This behaviour is advantageous as it allows monitoring progress, processing acquired data, and performing calculations simultaneously, enhancing efficiency.
You can use a onCleanup method to detect the ‘Ctrl+C’ command.
cleanupObj = onCleanup(cleanupFun) creates an object that, when destroyed, executes the function cleanupFun. MATLAB® implicitly clears all local variables at the termination of a function, whether by normal completion, or a forced exit, such as an error, or Ctrl+C.
PF following link:
3 件のコメント
Ninad
2023 年 8 月 31 日
Thanks for pointing out Walter. OnCleanup is a function provided for the similar purpose as needed by Shun.
Walter Roberson
2023 年 8 月 31 日
Except that Shun is working with a script, not a function. Shun would have to deliberately wrap code into a function to take advantage of onCleanup . Which would probably be acceptable to do.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Acquisition Toolbox Supported Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!