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:
Best Answer