Analog Outputs stops (without reason) ?!

Hey everybody!
I hope one of you can help me!
I am working on a Programm using DAQ-Toolbox and a National Instruments I/O USB Card. I am trying to output data continuously by using an analog outputobject. It got a Samplerate of 100 and 100 Values get enqueued before the object is started. After start a timerfunction enqueues new Data by using "putdata". The first 100 Samples are output fine but than the object stops though there are still 400 Values in the queue. It stops without any error message.
Why does the object stop?
In my opinion the object should run until no more data is left in the queue... .
If you need further information for an answer just let me know!

回答(3 个)

Usually USB buffers data until the USB packet size (close to 1000 bytes) is met. If your data is 2 bytes per sample, your buffer is getting drained until less than ~1000 bytes is left.
USB is not suitable for continual output of short packets -- at least not without getting in to details of USB that Mathworks has never exposed the user to.

1 个评论

Hey Walter!
Thanks for caring about my problem!
I dont think that it is a USB-problem because I use the following line to show in the command window how much Data is already IN the Hardware ready to be send.
readyToOutput=hObj.SamplesAvailable
And this command shows before the analog object stops that 400 Values are queued and waiting for being output. After the object stopped this property is set to zero.
So, what do you think?

请先登录,再进行评论。

Chirag Gupta
Chirag Gupta 2011-12-14
Can you post bit of the code? Also are you using the new Session based interface (R2011b) or the legacy interface ?
If you are using the legacy interface (analogoutput object) then you might need to set this property:

1 个评论

Hey Chirag!
Also thanks for caring about my problem!
I am using Matlab 2011. I can`t specify which version in detail at the moment as I am at home and not at college.
The problem occours in the part of the programm where I use the legacy-inferface. I am not using the session-based-interface in this part of the programm as I need continuous data to create a "Liveplot" of a stepresponse.
I think the session-based-aquisition isn`t made for getting continuously data for a "liveplot" or am I wrong?
I ve read already the documentation about "repeatoutput" and understood it that way that this function takes the already enqueued data an outputs it in a loop so many times as you enter. That makes this function worthless to me because I musst be able to enqueue NEW data due to the timer function.
So here is my code:
%% Declare continuous analog Output
% Outputobjekt erzeugen
gDyn_ao=analogoutput('nidaq','Dev3');
%Outputkanäle an Objekt anfügen
addchannel(gDyn_ao,1); % Heizer
%Sprung von
firstData(1)=gDyn_von;
%Initialen Datensatz erzeugen
for h=2:gDyn_sampleRate
firstData(h)=gDyn_bis; %Heizer
end
%TimerfunctionCallback deklarieren und ersten Datensatz übergeben
set(gDyn_ao,'TimerFcn',{@ao_enqueueMoreData,firstData});
%Set Time to trigger TimerfunctionCallback
period=((gDyn_ao.SampleRate*0.1)/gDyn_ao.SampleRate);
set(gDyn_ao,'TimerPeriod',period);
%Schreibrate setzen
set(gDyn_ao,'SampleRate',gDyn_sampleRate);
% Ersten Daten an analoges Device übergeben
firstData=firstData';
putdata(gDyn_ao,firstData);
%% Starte kontinuierliche, analoge Objekte
%Globale Variablen reseten
gDyn_databufferHeat=[];
gDyn_databufferTemp=[];
gDyn_timebuffer=[];
%Input- und Outputobjekt zusammenfassen
gDyn_analogObjects=[gDyn_ai gDyn_ao];
%I/O aktivieren
start(gDyn_analogObjects);
And the timerfunction:
% AnalogOUT-TimerCallback: getriggert neue Daten in den OutputPuffer schieben
function ao_enqueueMoreData(hObj,event,handles)
global gDyn_sampleRate;
global gDyn_von;
global gDyn_bis;
global zaehler;
zaehler=zaehler+1
readyToOutput=hObj.SamplesAvailable
%MaxQueueableData=hObj.MaxSamplesQueued
AusgegebenenSamples=hObj.SamplesOutput
%if (hObj.SamplesAvailable+lenth(nextData))>=hObj.MaxSamplesQueued
%if (hObj.SamplesAvailable+gDyn_sampleRate)>=hObj.MaxSamplesQueued
if hObj.SamplesAvailable>=gDyn_sampleRate*4
return
end
%generiere neue Outputdaten
for k=1:gDyn_sampleRate
nextData(k)=gDyn_bis; %Heizer
end
%Schiebe neue Daten in Puffer
nextData=nextData';
putdata(hObj,nextData);
Can you find any mistakes ?

请先登录,再进行评论。

Chirag Gupta
Chirag Gupta 2011-12-14
Looking at the documentation, it states that all the data must be queued using putdata before starting the analogoutput object.
So the TimerFcn will not work, unless you do the following: a) Change the TriggerType to Manual, b) and retrigger after putting more data.
A more convenient solution would be offered by Session based architecture which is perfect for this:
I am assuming you are doing both input and output simultaneoulsy! You can use Background operations to continuously queue data to to be output (using a DataRequired callback), example: http://www.mathworks.com/help/toolbox/daq/bsob84e-1.html#bsovlz7-1
You can also do both Input and Output simultaneously and do a live plot using 'DataAvailable' for inputs! http://www.mathworks.com/help/toolbox/daq/bsotkz_-1.html (You might want to use startBackground(), if you want the output data to happen in the background)

7 个评论

I suspected to hear something like this.
But I read in the documentation:
http://www.mathworks.de/help/toolbox/daq/f10-19090.html#f10-28979
Quotation:
"While the device object is running, you can continue to queue data."
I found the workaround concerning putting new data and "retrigger" the object too but I think this manner would cause some kind of gaps in my analog signal. So, this is no option.
To get ahead I will follow your tip an read the stuff about the session-based manner.
I would be great if you could give me the link where you found that ALL data musst be queued before starting!
http://www.mathworks.com/help/toolbox/daq/f10-11338.html
This comments that Data should be queued before starting the object, but then also continues to say what you have quoted.
It is possible that: You initially queued data, started the object and before new data could be finished being queued, the object stopped.
I would try Initially queuing more data, and then queuing smaller chunks. Also to check whether the object is still running after you have added more data!
But, I would still recommend moving over to Session based interface as it will allow for more flexibility and ease
Hey!
I followed your tip moving over to session-based-aquisition. I programmed the code in the morning. Now I`m facing another problem. It seems to be a general problem:
The sessionobject is being created and started. The sessionobject is configured this way that it triggers a function by the "DataAvailable" Event.
That works fine. BUT:
I want to plot the aquired data in the handles.axes1 but an error message says that handles.axes1 is unknown. When I debug the code, the handles-struct isn`t available in the workspace while this function executes. So, than its clear why I can`t access the object by using handles.axes1.
But what can I do to make the axes1-object available in this function?
I just want the handles-struct being available like in every other callback...
I hope you can help or give me a tip on this too.
Thanks!
Hey Tobias,
I would just pass the handles object to the callback function for DataAvailable.
Something like:
lh = s.addlistener('DataAvailable', {@plotData,handles});
then
function plotData(src,evt,handles)
...
http://www.mathworks.com/matlabcentral/answers/6258-thread-subject-nidaq-continuous-and-background-acquisition
Hey Chirag!
I tried this already before I asked this but I allways got an error message that said:
"One or More Output Arguments Not Assigned During Call to _feval"
I couldn't figure out what the reason for this was until one hour ago. I found an explanation of this error message and returned to the desciption of how to add a listener.
On that page:
"lh = addlistener('eventName', @(src, event) expr)"
In my code I used:
ln=liveSession.addlistener('DataAvailable',@(src,evt)GetNewData(src,evt,handles));
The function:
function GetNewData(src,evt,h)
...
Now everything works fine, thanks a lot for that!!!!
But I can't understand why it works fine because I can't understand the content of the brackets:
@(src,evt)GetNewData(src,evt,handles)
Are src and evt in the left brackets inputparameters? Or outputparameters? Or what else?
I'm asking because in other cases I only used something like this:
{@callback,handles}
And it worked as I wanted.
I am a little surprised at that! src and event are always inputs.
@(src,evn) Functioname (src,evnt, additionalargs) is one of the many ways to define a callback!
OK, thanks. :)

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

提问:

2011-12-14

Community Treasure Hunt

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

Start Hunting!

Translated by