1
votes

I would like to use Matlab's data acquisition toolbox to continuously send data to a device (sort of like an outer loop that is always running) and collect data from a sensor for a pre-determined duration after some time (the data acquire part being the inner loop). The continuous output part is working but I;m having no luck with the input. Any help will be much appreciated.

Fs=10000; % Sampling Frequency
timetoacquire=10; % Acquisition time
ss=daq.createSession('ni');
ss.Rate=Fs;
ss.DurationInSeconds=timetoacquire;
ss.addAnalogOutputChannel('Dev1',0,'Voltage');%Voltage to run pump

ss.addAnalogInputChannel('Dev1',1,'Voltage'); %Voltage from AnalogInputChannel

load VoltageOld;
load TimeOld;
timevect=linspace(min(TimeOld),max(TimeOld),Fs*max(TimeOld));
voltagevect=pchip(TimeOld,VoltageOld,timevect)';%Output Voltage Waveform

lh = ss.addlistener('DataRequired', ...
    @(src,event) src.queueOutputData(voltagevect));
ss.IsContinuous=true;
ss.queueOutputData(voltagevect);
ss.startBackground();

llh = ss.addlistener('DataAvailable', @plotData);
ss.queueOutputData(voltagevect);
[Voltagedata,timeStamps,triggerTime] = ss.startForeground;

% ss.stop();
% delete(lh);
1

1 Answers

0
votes

unforetunately matlab is getting poorer and poorer. Te documentations on session based daq is really aweful and requires serious and in-depth re-consideration. To me, it should be totally re-written, it gaves no information for developers.

You may try to have two separate sessions for input and output: sinput and soutput. It may work.