daq process usb-6008
Show older comments
how to acquire data from this code to process it in another operation in realtime
% 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',0, 'Voltage')
% set rate of scan 4 scans/second , run for 3 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/.001));
s.NotifyWhenDataAvailableExceeds = 200;
s.startBackground()
Answers (2)
Walter Roberson
on 18 Aug 2013
The line
h = s.addlistener('DataAvailable', @(src,event) plot(event.TimeStamps, event.Data/.001));
creates the (anonymous) callback function that will be called when data is available; in this case the data is plotted. You would change that line to do whatever processing you needed.
17 Comments
mado
on 18 Aug 2013
Walter Roberson
on 18 Aug 2013
function storedata(src, event)
global matrix_index
global matrix_data
if isempty(matrix_index); matrix_index = 0; matrix_data = zeros(1024,1)); end
newdata = event.Data;
matrix_data(matrix_index+1 : matrix_index + length(newdata)) = newdata;
matrix_index = matrix_index + length(newdata);
end
except that I would probably rewrite this to use shared variables instead of global variables.
mado
on 18 Aug 2013
Walter Roberson
on 18 Aug 2013
How did you add it as a listener? It should have been something like
h = s.addlistener('DataAvailable', @storedata);
mado
on 19 Aug 2013
mado
on 20 Aug 2013
Walter Roberson
on 20 Aug 2013
That line establishes the conditions under which the routine "storedata" will be automatically invoked. It would be the 'storedata' routine that would be responsible for getting the data to where you need it. The code I gave for 'storedata' saves the data to a global variable.
Walter Roberson
on 20 Aug 2013
In the routine that needs to access the data, you would add
global matrix_index
global matrix_data
and then the accumulated data so far would be
matrix_data(1:matrix_index)
mado
on 20 Aug 2013
Walter Roberson
on 20 Aug 2013
Single Ended signals use the physical wires differently than Differential. Single Ended use one signal wire (per direction) and a common ground and the signal on the single wire is measured relative to the common ground. Differential use two wires (per direction) and the signal is measured as the difference between the two wires.
mado
on 20 Aug 2013
Walter Roberson
on 20 Aug 2013
Edited: Walter Roberson
on 20 Aug 2013
Could you remind us which MATLAB version you are using?
And to check, is your USB-6008 board from National Instruments ?
Walter Roberson
on 20 Aug 2013
Could you show your current code that tries to use single-ended ?
mado
on 21 Aug 2013
Edited: Walter Roberson
on 21 Aug 2013
Walter Roberson
on 21 Aug 2013
As complete speculation: is it possible that you need channel 1 instead of channel 0 for your single ended measurement ?
mado
on 21 Aug 2013
0 votes
3 Comments
Walter Roberson
on 21 Aug 2013
Could you have a look at page 7 and verify your wiring? Differential 0 uses pins 2 and 3, diff 1 uses pins 5 and 6, diff 2 uses pins 8 and 9, diff 3 uses pins 11 and 12; Single ended 0 is pin 2, SE 1 is pin 5, SE 2 is pin 8, SE 3 is pin 11, SE 4 is pin 3, SE 5 is pin 6, SE 6 is pin 9, SE 7 is pin 12.
mado
on 21 Aug 2013
Edited: Walter Roberson
on 21 Aug 2013
Walter Roberson
on 21 Aug 2013
If you have checked your wiring, then I suggest you open a case with MATLAB technical support. I do not have the software or equipment to go further on this myself.
Categories
Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!