Filter löschen
Filter löschen

How to acquire and generate data using NI DAQ simultaneously on a continuous basis

7 Ansichten (letzte 30 Tage)
I have an NI input (9205) and NI output (9263) modules. I am trying to acquire and generate data in the same session but on a continuous basis. In this regard I referred to the tutorial provided for simultaneous acquisition and generation.
However when I try to do this on a continuous basis that is for an infinite amount of time I get the error : The data argument must contain one column for each output channel in the session.
I have pasted the code below.
function acquire_generate
clc;
global indata;
global outdata;
s3= daq.createSession('ni');
ch1= addAnalogInputChannel(s3,'cDAQ1Mod2','ai19','Voltage');
addAnalogOutputChannel(s3,'cDAQ1Mod7','ao0','Voltage');
ch1.InputType= 'SingleEnded';
s3.IsContinuous= true;
lh= s3.addlistener('DataAvailable',@plotData);% to plot acquire data in real time
s3.NotifyWhenDataAvailableExceeds=1000;
outdata= indata/2;
queueOutputData(s3,outdata);
lh1=s3.addlistener('DataRequired',@queueMoreData); % adding a listener to queue output data continuously
s3.startBackground();
while s3.IsRunning % to prevent Timeout
pause(0.5);
end
close(gcf);
figure(1);
plot(indata);
figure(2);
plot(outdata);
end
function plotData(src,event)
persistent localData;
global indata;
if(isempty(localData))
localData=[];
disp('acquiring starting');
end
plot(event.TimeStamps,event.Data);
localData= [localData;event.Data];
indata= localData;
if(max(event.Data)<5);
disp('Stopping acquire')
src.stop()
plot(event.TimeStamps,event.Data);
end
end
function queueMoreData(src,event)
global outdata;
queueOutputData(s3,outdata);
end
I am unable to figure out what I am doing wrong. Comments and insights will be appreciated. Thank you.
Regards,
Sri

Akzeptierte Antwort

Michael
Michael am 17 Okt. 2014
Bearbeitet: Michael am 17 Okt. 2014
I was having a different problem where I couldn't acquire for more than a few seconds.
for your problem, Srikrishnan, I'd start with the change below
ch(1) = addAnalogInputChannel(s3,'cDAQ1Mod2','ai19','Voltage');
ch(2) = addAnalogOutputChannel(s3,'cDAQ1Mod7','ao0','Voltage');
I was able to find that on Acquire Data and Generate Signals Simultaneously they say "When the session contains output channels, duration and number of scans become read-only properties of the session. The number of scans in a session is determined by the amount of data queued, and the duration is determined by s.ScansQueued/s.Rate.
Playing around with s.NotifyWhenDataAvailableExceeds fixed my problem.

Weitere Antworten (0)

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