daq process usb-6008
显示 更早的评论
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()
回答(2 个)
Walter Roberson
2013-8-18
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 个评论
mado
2013-8-18
Walter Roberson
2013-8-18
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
2013-8-18
Walter Roberson
2013-8-18
How did you add it as a listener? It should have been something like
h = s.addlistener('DataAvailable', @storedata);
mado
2013-8-19
mado
2013-8-20
Walter Roberson
2013-8-20
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
2013-8-20
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
2013-8-20
Walter Roberson
2013-8-20
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
2013-8-20
Walter Roberson
2013-8-20
编辑:Walter Roberson
2013-8-20
Could you remind us which MATLAB version you are using?
And to check, is your USB-6008 board from National Instruments ?
Walter Roberson
2013-8-20
Could you show your current code that tries to use single-ended ?
mado
2013-8-21
编辑:Walter Roberson
2013-8-21
Walter Roberson
2013-8-21
As complete speculation: is it possible that you need channel 1 instead of channel 0 for your single ended measurement ?
mado
2013-8-21
0 个投票
3 个评论
Walter Roberson
2013-8-21
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
2013-8-21
编辑:Walter Roberson
2013-8-21
Walter Roberson
2013-8-21
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.
类别
在 帮助中心 和 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!