I am collecting data using the Data Acquisition Toolbox. The data is collected in the background. I am collecting the data from 8 thermocouples and am able to call my listener to continually update my plot. However, I also need to keep a file, array, or some sort of log of the collected data. Here is my code:
daq.getDevices;
s = daq.createSession('ni');
s.Rate = 1.8;
s.DurationInSeconds = 60;
ch1 = addAnalogInputChannel(s,'cDAQ1Mod1','ai0','Thermocouple');
ch2 = addAnalogInputChannel(s,'cDAQ1Mod1','ai1','Thermocouple');
ch3 = addAnalogInputChannel(s,'cDAQ1Mod1','ai2','Thermocouple');
ch4 = addAnalogInputChannel(s,'cDAQ1Mod1','ai3','Thermocouple');
ch5 = addAnalogInputChannel(s,'cDAQ1Mod1','ai4','Thermocouple');
ch6 = addAnalogInputChannel(s,'cDAQ1Mod1','ai5','Thermocouple');
ch7 = addAnalogInputChannel(s,'cDAQ1Mod1','ai6','Thermocouple');
ch8 = addAnalogInputChannel(s,'cDAQ1Mod1','ai7','Thermocouple');
ch1.ThermocoupleType = 'T';
ch2.ThermocoupleType = 'T';
ch3.ThermocoupleType = 'T';
ch4.ThermocoupleType = 'T';
ch5.ThermocoupleType = 'T';
ch6.ThermocoupleType = 'T';
ch7.ThermocoupleType = 'T';
ch8.ThermocoupleType = 'T';
fid1 = fopen('log.bin','w');
lh = addlistener(s,'DataAvailable', @plotData);
lh1 = addlistener(s,'DataAvailable',@(src, event)logData(src, event, fid1));
s.NotifyWhenDataAvailableExceeds = 20;
s.startBackground();
fclose(fid1);
fid2 = fopen('log.bin','r');
[data,count] = fread(fid2,[8,inf],'double');
fclose(fid2);
The function plotData is:
function plotData(src,event)
plot(event.TimeStamps, event.Data)
legend('Outside Sensor 1','Middle Sensor 1','Middle Sensor 2','Middle Sensor 4', ...
'External Sensor 2','Outside Sensor 2','Middle Sensor 3','External Sensor 1')
end
The function logData is:
function logData(src, evt, fid)
data = [evt.TimeStamps, evt.Data]' ;
fwrite(fid,data,'double');
end
Any idea of how to keep a continuously update log of the data as it is collected while at the same time updating a log file of all the data points collectected?