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.
Why doesn't my listener for the background analog output change what values it queues?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ben Don
el 22 de Jun. de 2018
Respondida: Ben Don
el 26 de Jun. de 2018
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 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Data Acquisition Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!