daq process usb-6008
Afficher commentaires plus anciens
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()
Réponses (2)
Walter Roberson
le 18 Août 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 commentaires
mado
le 18 Août 2013
Walter Roberson
le 18 Août 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
le 18 Août 2013
Walter Roberson
le 18 Août 2013
How did you add it as a listener? It should have been something like
h = s.addlistener('DataAvailable', @storedata);
mado
le 19 Août 2013
mado
le 20 Août 2013
Walter Roberson
le 20 Août 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
le 20 Août 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
le 20 Août 2013
Walter Roberson
le 20 Août 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
le 20 Août 2013
Walter Roberson
le 20 Août 2013
Modifié(e) : Walter Roberson
le 20 Août 2013
Could you remind us which MATLAB version you are using?
And to check, is your USB-6008 board from National Instruments ?
Walter Roberson
le 20 Août 2013
Could you show your current code that tries to use single-ended ?
mado
le 21 Août 2013
Modifié(e) : Walter Roberson
le 21 Août 2013
Walter Roberson
le 21 Août 2013
As complete speculation: is it possible that you need channel 1 instead of channel 0 for your single ended measurement ?
mado
le 21 Août 2013
0 votes
3 commentaires
Walter Roberson
le 21 Août 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
le 21 Août 2013
Modifié(e) : Walter Roberson
le 21 Août 2013
Walter Roberson
le 21 Août 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.
Catégories
En savoir plus sur Data Acquisition Toolbox Supported Hardware dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!