Live data acquisition and store all data acquired

4 visualizzazioni (ultimi 30 giorni)
Nicolo' Nicolo'
Nicolo' Nicolo' il 20 Lug 2022
Risposto: Ayush il 3 Nov 2023
Hello, I have implemented a real time acquisition for acquiring 6 signals:
Dev = 'CDAQ2';
daq.getDevices;
s = daq.createSession('ni');
s.Rate = 100;
s.DurationInSeconds = 20;
DevTot = [Dev,'Mod6'];
ch1 = addAnalogInputChannel(s,DevTot,'ai0','Thermocouple');
ch1.ThermocoupleType = 'K';
ch2 = addAnalogInputChannel(s,DevTot,'ai1',"Thermocouple");
ch2.ThermocoupleType = "K";
ch.ch2 = ch2;
ch3 = addAnalogInputChannel(s,DevTot,'ai2',"Thermocouple");
ch3.ThermocoupleType = "K";
ch.ch3 = ch3;
DevTot = [Dev,'Mod7'];
ch4= addAnalogInputChannel(s,DevTot,'ai0',"Voltage");
ch.ch4 = ch4;
DevTot = [Dev,'Mod8'];
ch5=addAnalogInputChannel(s,DevTot,'ai1',"Current");
ch.ch5 = ch5;
DevTot=[Dev,'Mod5'];
ch6= addAnalogInputChannel(s,DevTot,'ai0',"Voltage");
ch.ch6 = ch6;
k=0;
lh = addlistener(s,'DataAvailable', @plotData);
s.NotifyWhenDataAvailableExceeds = 100;
s.startBackground();
function plotData(src,event,k)
plot(event.TimeStamps, event.Data)
legend('Temperature Stack','Ambient Temperature','Air Temperature' , 'Voltage','H2 flow','Current')
H(1+20*k:20+20*k)=event.Data;
k=k+1;
src.UserData=H;
end
I would like to store all the data acquisition (2000X6 samples) in the matrix H and then in d.UserData, but until now I store in this variable only the last 100X6 samples.
Thanks in advance!

Risposte (1)

Ayush
Ayush il 3 Nov 2023
Hey Nicolo,
I see that you are working on a data acquisition project in MATLAB by using the Data Acquisition Toolbox to connect to a National Instruments device and acquire 6 analog signals. You are also using a callback function to plot the data and store all the data acquisition (2000X6 samples) in the matrix “H” and then in “d.UserData”, but the provided code is storing only the last 100X6 samples in it.
One possible reason for this is, you are overwriting the previous values every time the callback function is executed. To avoid this, you need to use persistent variables or global variables to keep track of the data and the index “k”.
Please refer to the MathWorks documentation link below for more information on Data Acquisition toolbox and persistent variables:
  1. DAQ Toolbox : https://in.mathworks.com/help/daq/getting-started-with-data-acquisition-toolbox.html
  2. Persistent Variables: https://in.mathworks.com/help/matlab/ref/persistent.html
Hope this helps!
Regards,
Ayush Goyal

Categorie

Scopri di più su Analog Input and Output in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by