How to continuously record data using data acquisition until programmatically told to stop.
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I have a feeling i am being stupid and missing something obvious but I cant quite get the code to work how I need it.
I am using the Data Aquisition toolbox, connecting to and reading anologue data from a NI device. I can connect fine and can record data okay but I can only seem to record data for a given amount of time or a given number of data points, both of which I don't know and changes from scan to scan. Ideally I would use something like the simplified code below were i start recording, I then carryout an other fucntion, which when finished stops the data recording before I read the data into the workspace :
dqlist = daqlist("ni");
dq = daq("ni");
dq.Rate=200000;
addinput(dq, dqlist.DeviceID, "ai0", "Voltage");
for i = 1:10000
start(dq,"continuous");
Some_other_function
stop(dq);
output{i} = read(dq); %%% read the data collected between the start and stop functions
end
Obviously I could just specify a record time/data aquire that is far bigger than needed but as this loop is happening thousands of times it isnt efficent or practical. I also need to record the data at the high inbuilt hardware speed of 200,000 samples a sec so I can't have a parrelel loop which records a single sample at a time.
Any help is much appricated, I am sure this is doable as there is a start and stop functions but I couldn't find an example which works exactly how it need.
Thanks
James
0 comentarios
Respuestas (1)
sai charan sampara
el 27 de Oct. de 2023
Hello James,
I understand that you are trying to record data using data acquisition and want it to continue until it is programmatically told to stop.
One possible fix that can be thought of from the information available in the question is to use a conditional loop. A “while” loop can be set up in which data acquisition is done continuously until a certain condition is violated. As per your requirement a logical variable can be defined that is true if data needs to be acquired and once data acquisition needs to be stopped it is set to false. This can be set as the condition for running of the while loop.
A “while” loop is advantageous over “for” loop that you need not specify any number of iterations and at the same time provides the functionality of working in a loop. The condition in the while loop can be a Boolean algebraic function of several logical variables and can be used to implement more complex conditions. A break condition in “for” loop can also be used as an exit condition from the data acquisition.
You can refer to the below documentation to learn more about while loop:
Hope this helps.
Thanks,
Charan.
0 comentarios
Ver también
Categorías
Más información sobre Data Acquisition Toolbox Supported Hardware en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!