Effacer les filtres
Effacer les filtres

How can I change the buffer size on NI-Daq device, using session-based interface ?

7 vues (au cours des 30 derniers jours)
Marthe Curtit
Marthe Curtit le 1 Avr 2014
Hello, I'm using the session-based interface to acquire datas from an NI-USB Daq-device. I'm processing datas during acquisition, using a listener. I would like to change the length of the events, recieved during acquisition. In this exemple, would it be possible to change the size of event.data, recieved in the function plotData ?
s = daq.createSession('ni');
addAnalogInputChannel(s,'cDAQ1Mod1', 'ai0', 'Voltage');
lh = addlistener(s,'DataAvailable', @plotData);
function plotData(src,event)
plot(event.TimeStamps, event.Data)
end
Thank you,

Réponses (1)

Shyam Sangaraju
Shyam Sangaraju le 24 Juil 2014
Modifié(e) : Walter Roberson le 8 Juil 2019
You can use “getdata” function to acquire data of specific size. Following sample code demonstrates how to use “getdata” function:
>> ai = analoginput('nidaq','Dev1')
>> addchannel(ai,0);
>> set(ai,'SamplesAcquiredFcnCount',4)
>> set(ai,'SamplesAcquiredFcn',@mydaqcallback);
Where @mydaqcallback consists of the following code:
function mydaqcallback(obj, event)
% number of data samples to acquire
data = getdata(obj,obj.SamplesAcquiredFcnCount);
% you can execute your logic here.
Where ‘obj’ is an analog input object.
‘obj. SamplesAcquiredFcnCount’ is number of samples to extract.
‘data’ is m-by-n array, where m is the number of samples extracted and n is the number of channels contained by obj.

Catégories

En savoir plus sur Simultaneous and Synchronized Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by