Why doesn't my listener for the background analog output change what values it queues?

2 ビュー (過去 30 日間)
Ben Don
Ben Don 2018 年 6 月 22 日
回答済み: Ben Don 2018 年 6 月 26 日
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:
  1. Additional Arguments for Callback Function
  2. Generate continuous background analog output

採用された回答

Ben Don
Ben Don 2018 年 6 月 26 日
I eventually got this working using the functions evalin('ws','var') and assignin('ws','var',value). Hopefully these two functions are useful to whomever goes looking for anything related to the topic above.
  1. evalin()
  2. assignin()

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Data Acquisition Toolbox についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by