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_generateclc;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);endend 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
Best Answer