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 个)

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 个评论

if i want to take the data and store it as a matrix ???
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.
executing this function give error message
Not enough input arguments.
How did you add it as a listener? It should have been something like
h = s.addlistener('DataAvailable', @storedata);
that line want give me values that i can process ,i need to have values in a matrix or i can sent it to workspace, i execute it and it gave
h =
event.listener handle
Package: event
Properties:
Source: {[1x1 daq.ni.Session]}
EventName: 'DataAvailable'
Callback: @storedata
Enabled: 1
Recursive: 0
Methods, Events, Superclasses
any help?
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.
here is all the code i don't understand how to get data to use it in math operation after storing ," storedata" can't be used alone on single line .
how could "storedata" be able to store and restore ??
%%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', @storedata); s.NotifyWhenDataAvailableExceeds = 200; s.startBackground()
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)
thank you it's working now . i have another problem in
% v.TerminalConfig = ' Differential';
when i changed it to singleEnded it don't read real signal idon't know why .
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.
ok i have done that and both of sinlended and diff are working with labview but here just only differential working
Could you remind us which MATLAB version you are using?
And to check, is your USB-6008 board from National Instruments ?
mado
mado 2013-8-20
编辑:mado 2013-8-20
MATLAB Version: 7.14.0.739 (R2012a) Operating System: Microsoft Windows 7 Version 6.1 (Build 7600) Java Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode .
yes , it's NI board
Could you show your current code that tries to use single-ended ?
just i changed differential to SingleEnded
%%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 = ' SingleEnded';
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()
global matrix_index
global matrix_data
matrix_data(1:matrix_index)
As complete speculation: is it possible that you need channel 1 instead of channel 0 for your single ended measurement ?

请先登录,再进行评论。

mado
mado 2013-8-21

0 个投票

I need to use both of channel 0 and 1 , will it make a difference ?

3 个评论

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
mado 2013-8-21
编辑:Walter Roberson 2013-8-21
ok, i know that Analog Input Channels 0 to 7—For single-ended measurements, each signal is an analog input voltage channel. For differential measurements, AI 0 and AI 4 are the positive and negative inputs of differential analog input channel 0. The following signal pairs also form differential input channels: <AI 1, AI 5>, <AI 2, AI 6>, and <AI 3,AI 7>.
how to verify writing , i think it's written right
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 的更多信息

标签

提问:

2013-8-18

Community Treasure Hunt

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

Start Hunting!

Translated by