usb 6008 to acquire signal online

1 次查看(过去 30 天)
mado
mado 2014-1-28
i am using usb 6008 to acquire signal using this code and i want to use the signal in a process in m file while reading
%%get connected devices
d = daq.getDevices
%create session
s = daq.createSession('ni')
%add analog channel s.addAnalogInputChannel('ID',channel num, 'measurement type')
s.addAnalogInputChannel('dev1','ai0', 'Voltage')
% set rate of scan 4 scans/second , run for 30 seconds
s.Rate=1000;
s.DurationInSeconds=30;
v= s.Channels(1);
set(v)
%_____________________________
v.TerminalConfig = ' Differential';
v.Coupling = ' DC';
%start continuous aquisition and plot
h = s.addlistener('DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));
s.NotifyWhenDataAvailableExceeds = 200;
s.startBackground()
s.wait()
delete (h)
h = s.addlistener('DataAvailable', @storedata);s.NotifyWhenDataAvailableExceeds = 200;
s.startBackground()
  2 个评论
Walter Roberson
Walter Roberson 2014-1-28
What is the question? Are you encountering an error?
mado
mado 2014-1-28
编辑:mado 2014-1-28
there is no error , i want to use the signal in a process in m file while reading . on this status now i got the data after finishing reading .this code can't give results for other operations before finishing reading.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2014-1-28
The addlistener calls show you how you can proceed, with two examples given. The first is for the case where you want to plot as you go along, and the second is for the case where you want to store the data as you go along. You could use a different listener that did whatever you needed to do.
The s.wait() is the call that results in the command line waiting until s.DurationInSeconds worth of data has been plotted. If that wait is not there then the data will be served up by the listener calls starting any time after s.startBackground is called. If you let the duration of collecting be infinite then you can go ahead and make whatever calls you need, with the listener called as s.NotifyWhenDataAvailableExceeds measurements become available.

类别

Help CenterFile 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!

Translated by