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

Antworten (2)

Walter Roberson
Walter Roberson am 18 Aug. 2013

0 Stimmen

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 Kommentare

mado
mado am 18 Aug. 2013
if i want to take the data and store it as a matrix ???
Walter Roberson
Walter Roberson am 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
mado am 18 Aug. 2013
executing this function give error message
Not enough input arguments.
Walter Roberson
Walter Roberson am 18 Aug. 2013
How did you add it as a listener? It should have been something like
h = s.addlistener('DataAvailable', @storedata);
mado
mado am 19 Aug. 2013
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
mado
mado am 20 Aug. 2013
any help?
Walter Roberson
Walter Roberson am 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.
mado
mado am 20 Aug. 2013
Bearbeitet: mado am 20 Aug. 2013
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()
Walter Roberson
Walter Roberson am 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
mado am 20 Aug. 2013
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 .
Walter Roberson
Walter Roberson am 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
mado am 20 Aug. 2013
ok i have done that and both of sinlended and diff are working with labview but here just only differential working
Walter Roberson
Walter Roberson am 20 Aug. 2013
Bearbeitet: Walter Roberson am 20 Aug. 2013
Could you remind us which MATLAB version you are using?
And to check, is your USB-6008 board from National Instruments ?
mado
mado am 20 Aug. 2013
Bearbeitet: mado am 20 Aug. 2013
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
Walter Roberson
Walter Roberson am 20 Aug. 2013
Could you show your current code that tries to use single-ended ?
mado
mado am 21 Aug. 2013
Bearbeitet: Walter Roberson am 21 Aug. 2013
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)
Walter Roberson
Walter Roberson am 21 Aug. 2013
As complete speculation: is it possible that you need channel 1 instead of channel 0 for your single ended measurement ?

Melden Sie sich an, um zu kommentieren.

mado
mado am 21 Aug. 2013

0 Stimmen

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

3 Kommentare

Walter Roberson
Walter Roberson am 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
mado am 21 Aug. 2013
Bearbeitet: Walter Roberson am 21 Aug. 2013
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
Walter Roberson
Walter Roberson am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Acquisition Toolbox Supported Hardware finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 18 Aug. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by