Borrar filtros
Borrar filtros

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

7 visualizaciones (últimos 30 días)
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,

Respuestas (1)

Shyam Sangaraju
Shyam Sangaraju el 24 de Jul. de 2014
Editada: Walter Roberson el 8 de Jul. de 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.

Categorías

Más información sobre Simultaneous and Synchronized Operations 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!

Translated by