Azzera filtri
Azzera filtri

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

7 visualizzazioni (ultimi 30 giorni)
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,

Risposte (1)

Shyam Sangaraju
Shyam Sangaraju il 24 Lug 2014
Modificato: Walter Roberson il 8 Lug 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.

Categorie

Scopri di più su Simultaneous and Synchronized Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by