Triggering with a DAQ board--how do I pull data out of startBackground and tell MATLAB to take a few more samples?
5 次查看(过去 30 天)
显示 更早的评论
Good afternoon,
I'm having some trouble updating some old NI interfacing code (for a PCI-6115) to the new session based interface in 2011b.
Here's the basic idea: I'd like to run my DAQ board like an oscilloscope, so I set it to passively scan, wait until my signal passes some threshold value, and then record a sample for X length of time (or NUMBEROFSAMPLES number of samples).
I've read through http://www.mathworks.com/products/daq/demos.html?file=/products/demos/shipping/daq/demo_compactdaq_background_acquisition.html and that's given me the basic idea of what needs to be done, but I'm still having trouble getting my code to work properly.
Here's my code %Initial routines for creating the daq session and initializing the channels (device = daq.createSession('ni'), etc.) % thresh = 2; % 2V threshhold value
device.NotifyWhenDataAvailableExceeds = NUMBEROFSAMPLES;
lh = device.addlistener('DataAvailable', @(src, event) stopwhenpassthresh(src, event, thresh));
device.IsContinuous = true;
device.startBackground;
function stopwhenpassthresh(src, event, thresh)
if any(event.Data > thresh)
disp('Triggered')
src.stop;
end
end
Some questions that I have: - How do I pull event.Data and event.TimeStamps out from the stopwhenpassthresh function into something I can process? - If it was at all possible, I'd like to be able to tell my code that when we pass the threshhold value, it should take one extra run of data (and then I can lop off the extra data afterwards). It'd also be nice if I could get a bit more control over the pre-trigger data as well.
Thank you for your help, Paul
0 个评论
采纳的回答
Chirag Gupta
2011-12-21
This may be of help! I proposed 3 different methods, chose whats best in your case: http://www.mathworks.com/matlabcentral/answers/6258-thread-subject-nidaq-continuous-and-background-acquisition
更多回答(1 个)
Walter Roberson
2011-12-20
Use the same data sharing techniques as for graphic callbacks; see http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
7 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!