Sending Desired Signal to DAQ Device with Data Acquisition Toolbox

10 vues (au cours des 30 derniers jours)
Hakan Caldag
Hakan Caldag le 6 Mar 2018
Commenté : Hakan Caldag le 10 Sep 2018
Hey everyone, I am working on controlling current sent to a pair of Helmholtz coils through Matlab with Data Acquisition Toolbox. Looking at related documentation, I was able to generate code that would queue desired signal to NI DAQ device and sustain it but what I want to do is the flexibility of changing the current I send to the device whenever desired. When the data queued with queueOutputData() is finished, the program seems to queue back whatever is in the listener. I actually want it to continue with whatever I queued until I change it and if I change it I want to continue with that. Do I have to update the listener and if so how can I do that? Also, I understand that when I queue a certain signal, I can't cancel it and replace with another signal before it's processed. Is there any way I can overcome it? Below I share the part of the code that generates desired signal, initiates a listener and queues some output data.
s=daq.createSession('ni');
out1=addAnalogOutputChannel(s,'Dev1',0,'Voltage');
s.Rate = 20000; %Device initialization
f=5;
w=2*pi*f;
out1_amp=0.8;
out2_amp=out1_amp;
out1_signal=out1_amp*sin(linspace(0,2*pi*f,s.Rate+1)');
out1_signal(end)=[]; %Signal generation
lh=addlistener(s,'DataRequired', @(src, event) src.queueOutputData([out1_signal]));
s.IsContinuous=true;
queueOutputData(s,repmat([out1_signal],5,1));
s.startBackground();
  6 commentaires
Walter Roberson
Walter Roberson le 7 Sep 2018
Please post your code, Dora.
Hakan Caldag
Hakan Caldag le 10 Sep 2018
I was able to solve this problem somehow but I cannot guarantee that it works at all times and I am not sure which one of the things below made it work. And since I do not have access to the code right now, I may be missing a few things.
-Firstly, instead of using "addlistener" function, I use "listener" function to define my listener.
- I stop() and release() whenever I want to update my signal.
- After this, I remember redefining the listener based on the new signal but I am not sure whether I delete() the listener and then redefine with listener() function or overwrite it without deleting.
I hope these help.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by