usb 6008 to acquire signal online

2 views (last 30 days)
mado
mado on 28 Jan 2014
Answered: Walter Roberson on 28 Jan 2014
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 Comments
Walter Roberson
Walter Roberson on 28 Jan 2014
What is the question? Are you encountering an error?
mado
mado on 28 Jan 2014
Edited: mado on 28 Jan 2014
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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 28 Jan 2014
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.

Categories

Find more on Simultaneous and Synchronized Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!