Stop Data Acquisition when Needed
Hello,
I am building a data aquisition program using NI devices. I developed a program using the data aquisition toolbox, however the code that I have needs a run time as input which is only when I know the data aquisition time.
However in cases when I need to stop the data aquisition before the set input time, I am unable to do so before the complete run is done.
Is there a way to stop the program and still have access to the aquired data because if I stop the program, the workspace clears out and there in no data there or is there a way I can continously add data into a buffer which the data is being read so that even if the program is stipped, the aquired data is accessible.
I have attached my code for review.
close all
clear all
clc
%% Create a data acquisition session
daqSession = daq.createSession(‘ni’);
%% Add channels specified by subsystem type and device
daqSession.addAnalogInputChannel(‘Dev1′,’ai0′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai1′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai2′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai3′,’Bridge’);
%% Configure properties
daqSession.Rate = 1653;
daqSession.IsContinuous = 1;
hlistener = daqSession.addlistener(‘DataAvailable’,@(src,event) plot(event.TimeStamps, event.Data));
daqSession.IsContinuous = 0;
daqSession.DurationInSeconds = 1800;
daqSession.Channels(1).BridgeMode = ‘Full’;
daqSession.Channels(1).ExcitationVoltage = 5;
daqSession.Channels(1).NominalBridgeResistance = 1;
daqSession.Channels(1).Name = ‘Kulite 1’;
daqSession.Channels(2).BridgeMode = ‘Full’;
daqSession.Channels(2).NominalBridgeResistance = 1;
daqSession.Channels(2).Name = ‘Kulite2’;
daqSession.Channels(3).BridgeMode = ‘Full’;
daqSession.Channels(3).NominalBridgeResistance = 1;
daqSession.Channels(3).Name = ‘Kulite3’;
daqSession.Channels(4).BridgeMode = ‘Full’;
daqSession.Channels(4).NominalBridgeResistance = 1;
daqSession.Channels(4).Name = ‘Kulite4’;
%Read supplied voltage
V=daqSession.Channels(1).ExcitationVoltage;
%% Run the data acquisition session
[data,time] = daqSession.startForeground();
figure
plot(time,data)
%Take values from DAQ Matrix
V1=data(:,1);
V2=data(:,2);
V3=data(:,3);
V4=data(:,4);
%Create Matrix for other Time and Pressure Values
Voltagedata=[time,V1,V2,V3,V4];
fileName = sprintf(‘RawVData_%s.csv’, datestr(now, ‘yyyymmdd_HHMMSS’))
writematrix(Voltagedata,fileName)
%% Disconnect from the device
daqSession.release();
delete(daqSession);
clear daqSession;Hello,
I am building a data aquisition program using NI devices. I developed a program using the data aquisition toolbox, however the code that I have needs a run time as input which is only when I know the data aquisition time.
However in cases when I need to stop the data aquisition before the set input time, I am unable to do so before the complete run is done.
Is there a way to stop the program and still have access to the aquired data because if I stop the program, the workspace clears out and there in no data there or is there a way I can continously add data into a buffer which the data is being read so that even if the program is stipped, the aquired data is accessible.
I have attached my code for review.
close all
clear all
clc
%% Create a data acquisition session
daqSession = daq.createSession(‘ni’);
%% Add channels specified by subsystem type and device
daqSession.addAnalogInputChannel(‘Dev1′,’ai0′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai1′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai2′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai3′,’Bridge’);
%% Configure properties
daqSession.Rate = 1653;
daqSession.IsContinuous = 1;
hlistener = daqSession.addlistener(‘DataAvailable’,@(src,event) plot(event.TimeStamps, event.Data));
daqSession.IsContinuous = 0;
daqSession.DurationInSeconds = 1800;
daqSession.Channels(1).BridgeMode = ‘Full’;
daqSession.Channels(1).ExcitationVoltage = 5;
daqSession.Channels(1).NominalBridgeResistance = 1;
daqSession.Channels(1).Name = ‘Kulite 1’;
daqSession.Channels(2).BridgeMode = ‘Full’;
daqSession.Channels(2).NominalBridgeResistance = 1;
daqSession.Channels(2).Name = ‘Kulite2’;
daqSession.Channels(3).BridgeMode = ‘Full’;
daqSession.Channels(3).NominalBridgeResistance = 1;
daqSession.Channels(3).Name = ‘Kulite3’;
daqSession.Channels(4).BridgeMode = ‘Full’;
daqSession.Channels(4).NominalBridgeResistance = 1;
daqSession.Channels(4).Name = ‘Kulite4’;
%Read supplied voltage
V=daqSession.Channels(1).ExcitationVoltage;
%% Run the data acquisition session
[data,time] = daqSession.startForeground();
figure
plot(time,data)
%Take values from DAQ Matrix
V1=data(:,1);
V2=data(:,2);
V3=data(:,3);
V4=data(:,4);
%Create Matrix for other Time and Pressure Values
Voltagedata=[time,V1,V2,V3,V4];
fileName = sprintf(‘RawVData_%s.csv’, datestr(now, ‘yyyymmdd_HHMMSS’))
writematrix(Voltagedata,fileName)
%% Disconnect from the device
daqSession.release();
delete(daqSession);
clear daqSession; Hello,
I am building a data aquisition program using NI devices. I developed a program using the data aquisition toolbox, however the code that I have needs a run time as input which is only when I know the data aquisition time.
However in cases when I need to stop the data aquisition before the set input time, I am unable to do so before the complete run is done.
Is there a way to stop the program and still have access to the aquired data because if I stop the program, the workspace clears out and there in no data there or is there a way I can continously add data into a buffer which the data is being read so that even if the program is stipped, the aquired data is accessible.
I have attached my code for review.
close all
clear all
clc
%% Create a data acquisition session
daqSession = daq.createSession(‘ni’);
%% Add channels specified by subsystem type and device
daqSession.addAnalogInputChannel(‘Dev1′,’ai0′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai1′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai2′,’Bridge’);
daqSession.addAnalogInputChannel(‘Dev1′,’ai3′,’Bridge’);
%% Configure properties
daqSession.Rate = 1653;
daqSession.IsContinuous = 1;
hlistener = daqSession.addlistener(‘DataAvailable’,@(src,event) plot(event.TimeStamps, event.Data));
daqSession.IsContinuous = 0;
daqSession.DurationInSeconds = 1800;
daqSession.Channels(1).BridgeMode = ‘Full’;
daqSession.Channels(1).ExcitationVoltage = 5;
daqSession.Channels(1).NominalBridgeResistance = 1;
daqSession.Channels(1).Name = ‘Kulite 1’;
daqSession.Channels(2).BridgeMode = ‘Full’;
daqSession.Channels(2).NominalBridgeResistance = 1;
daqSession.Channels(2).Name = ‘Kulite2’;
daqSession.Channels(3).BridgeMode = ‘Full’;
daqSession.Channels(3).NominalBridgeResistance = 1;
daqSession.Channels(3).Name = ‘Kulite3’;
daqSession.Channels(4).BridgeMode = ‘Full’;
daqSession.Channels(4).NominalBridgeResistance = 1;
daqSession.Channels(4).Name = ‘Kulite4’;
%Read supplied voltage
V=daqSession.Channels(1).ExcitationVoltage;
%% Run the data acquisition session
[data,time] = daqSession.startForeground();
figure
plot(time,data)
%Take values from DAQ Matrix
V1=data(:,1);
V2=data(:,2);
V3=data(:,3);
V4=data(:,4);
%Create Matrix for other Time and Pressure Values
Voltagedata=[time,V1,V2,V3,V4];
fileName = sprintf(‘RawVData_%s.csv’, datestr(now, ‘yyyymmdd_HHMMSS’))
writematrix(Voltagedata,fileName)
%% Disconnect from the device
daqSession.release();
delete(daqSession);
clear daqSession; nidaq, data acquisition MATLAB Answers — New Questions