Filter löschen
Filter löschen

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

7 Ansichten (letzte 30 Tage)
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,

Antworten (1)

Shyam Sangaraju
Shyam Sangaraju am 24 Jul. 2014
Bearbeitet: Walter Roberson am 8 Jul. 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.

Kategorien

Mehr zu Simultaneous and Synchronized Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by