Why doesn't my listener for the background analog output change what values it queues?
이전 댓글 표시
I want to dynamically update the values in the analog output data queue. I've included my attempt below. Initially, the variable called 'signal' is a vector of values going from 0 to 5 (and back to 0). However, I change the contents of 'signal' with all 1's. Nonetheless, with a scope connected to the AO, it simply rises from 0 to 5 again and again. This doesn't go to 1 after the initial queue runs out.
%Initialize DA Device 'Dev1' - PCI-6713 - AO
daqreset %reset daq
sAO = daq.createSession('ni'); %create a DAQ session for NI card
sAO.Rate = 100; %Update AO 100 times per second
ch = addAnalogOutputChannel(sAO,'Dev1', 'ao1', 'Voltage'); %Add daq device and channel to session
signal = [linspace(0,5,299)';0]; %Incremental values from 0 to 5V ending back at 0.
queueOutputData(sAO,signal) %buffer some output
%Start AI/AO tasks
sAO.IsContinuous = true; %NECESSARY AND NOT IN DOCUMENTATION
lhAO = addlistener(sAO,'DataRequired', @(src,event)newNumbers(src,event,signal));
startBackground(sAO);
%Change values to buffer in the output queue
signal = ones(300,1);
pause(); %await keypress
delete(lhAO)
stop(sAO)
disp('Done')
function newNumbers(src, event, varargin)
signal = varargin{1};
queueOutputData(src,signal);
end
Since resources are limited on the topic I'm happy to point you to my resources for developing this code:
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Acquisition Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!