<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/272423</link>
    <title>MATLAB Central Newsreader - DAQ SamplesAvailable never &gt;0 after getdata</title>
    <description>Feed for thread: DAQ SamplesAvailable never &gt;0 after getdata</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 09 Feb 2010 15:56:02 -0500</pubDate>
      <title>DAQ SamplesAvailable never &gt;0 after getdata</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/272423#715380</link>
      <author>Dave Hathaway</author>
      <description>I am prototyping a data acquisition system by using the 'winsound' device.  The actual device will operate at 200hz and I will need to collect the 200 samples each second, do some processing each minute, and more at each hour.  That's a little background.&lt;br&gt;
&lt;br&gt;
Right now, I'm trying to collect data from the winsound device at 5000 samples per second.  I've borrowed code from the daqwaterfall example in the Complete Application Development class.  My thought is to collect the data each second, and I have the TimerFcn being called reliably.&lt;br&gt;
&lt;br&gt;
In it, I am using the SamplesAvailable property to see when the data is ready.  I use getdata to extract the data...&lt;br&gt;
&lt;br&gt;
% timer function&lt;br&gt;
function localtimer_callback(obj,event)&lt;br&gt;
&lt;br&gt;
if obj.SamplesAvailable &amp;gt; 0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x = getdata(obj);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;% do stuff with x&lt;br&gt;
end&lt;br&gt;
...&lt;br&gt;
&lt;br&gt;
The problem is that when I use getdata rather than peekdata, the SamplesAvailable is always at 0.  The TimerFcn keeps popping along, but there are never any SamplesAvailable.&lt;br&gt;
&lt;br&gt;
I have tried this with the SamplesAcquiredFcn as well, with the same result.&lt;br&gt;
&lt;br&gt;
What am I doing wrong?&lt;br&gt;
&lt;br&gt;
Dave</description>
    </item>
    <item>
      <pubDate>Wed, 10 Feb 2010 13:03:04 -0500</pubDate>
      <title>Re: DAQ SamplesAvailable never &gt;0 after getdata</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/272423#715678</link>
      <author>Sherryl Radbil</author>
      <description>Hi Dave ,&lt;br&gt;
The callback snippet looks reasonable but there isn't enough code here to know if you're setting up the acquisition correctly.&lt;br&gt;
Whittle your program down to the absolute minimum lines of code to show both the main loop and the callback and post it here (you should be able to do that in under 20 lines of code).&lt;br&gt;
Also, you can post the output of running&lt;br&gt;
daqsupport&lt;br&gt;
(though you can omit the long section with the path - you don't have a path problem it seems).&lt;br&gt;
&lt;br&gt;
As long as you've set the acquisition to go as long as you need either via SamplesPerTrigger or TriggerRepeat and started this should work.&lt;br&gt;
All the best,&lt;br&gt;
Sherryl</description>
    </item>
    <item>
      <pubDate>Wed, 10 Feb 2010 14:26:04 -0500</pubDate>
      <title>Re: DAQ SamplesAvailable never &gt;0 after getdata</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/272423#715710</link>
      <author>Dave Hathaway</author>
      <description>&quot;Sherryl Radbil&quot; &amp;lt;sherryl.radbil.dontspamme@mathworks.com&amp;gt; wrote in message &amp;lt;hkuaq8$mhm$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
*snipped*&lt;br&gt;
&amp;gt; As long as you've set the acquisition to go as long as you need either via SamplesPerTrigger or TriggerRepeat and started this should work.&lt;br&gt;
&amp;gt; All the best,&lt;br&gt;
&amp;gt; Sherryl&lt;br&gt;
&lt;br&gt;
Thanks Sherryl,&lt;br&gt;
&lt;br&gt;
I think I found the problem.&lt;br&gt;
&lt;br&gt;
ai = analoginput('winsound', 0);&lt;br&gt;
addchannel(ai, 1:2);&lt;br&gt;
&lt;br&gt;
set(ai, 'SampleRate', 5000);&lt;br&gt;
set(ai, 'SamplesPerTrigger', 5000);&lt;br&gt;
set(ai, 'TriggerRepeat', inf);&lt;br&gt;
set(ai, 'TriggerType', 'manual');&lt;br&gt;
set(ai, 'TimerFcn', @localtimer_callback);&lt;br&gt;
set(ai, 'TimerPeriod', 0.5);  &lt;br&gt;
set(ai, 'BufferingConfig',[5000*2,20]);&lt;br&gt;
set(ai, 'SamplesAcquiredFcn', @localacquired_callback);&lt;br&gt;
set(ai, 'SamplesAcquiredFcnCount', 5000);&lt;br&gt;
start(ai);&lt;br&gt;
trigger(ai);&lt;br&gt;
&lt;br&gt;
All the examples had the TriggerRepeat value as 1.  Then they would use peekdata to grab samples without actually exhausting that 1.  When I set the value to 'inf', it started filling the buffer non-stop.&lt;br&gt;
&lt;br&gt;
I hope this solves my problem.  I'm not sure what of the above I really need, but I have a start towards development.  Any thoughts are appreciated.&lt;br&gt;
&lt;br&gt;
Thanks again,&lt;br&gt;
&lt;br&gt;
Dave</description>
    </item>
    <item>
      <pubDate>Thu, 11 Feb 2010 13:24:02 -0500</pubDate>
      <title>Re: DAQ SamplesAvailable never &gt;0 after getdata</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/272423#716019</link>
      <author>Sherryl Radbil</author>
      <description>Hi Dave,&lt;br&gt;
Glad you have it working.&lt;br&gt;
I see two issues with your code.&lt;br&gt;
&lt;br&gt;
You should not use both TimerFcn and SamplesAcquiredFcn.&lt;br&gt;
Choose one.&lt;br&gt;
&lt;br&gt;
Many programs call getdata() from within a callback and find that they can't keep up when using SamplesAcquiredFcn and SamplesAcquiredFcnCount when data processing time exceeds the data inflow time.&lt;br&gt;
As an alternative they should use TimerFcn and TimerPeriod.&lt;br&gt;
The difference is that SamplesAcquiredFcn callbacks queue up and are never lost while if a TimerFcn callback has not yet executed and another one comes in the previous one is discarded so there is never a backlog. In either case getdata() should get enough data from the engine so that the program does not fall behind. You can check the SamplesAvailable property from within the callback to see how much data is actually available.&lt;br&gt;
As with all these programs it is impossible to give an exact formula on how to set things up. It will depend on the SampleRate and the actual PC and acquisition device in use. &lt;br&gt;
&lt;br&gt;
Also, I would suggest removing the line:&lt;br&gt;
set(ai, 'BufferingConfig',[5000*2,20]);&lt;br&gt;
The Data Acquisition Engine will compute the buffering config values for you and unless you are trying to overcome a specific issue you are better off letting the engine do the calcluation.&lt;br&gt;
&lt;br&gt;
Other than that your code looks good.&lt;br&gt;
Happy acquiring!&lt;br&gt;
Sherryl</description>
    </item>
    <item>
      <pubDate>Thu, 11 Feb 2010 14:40:21 -0500</pubDate>
      <title>Re: DAQ SamplesAvailable never &gt;0 after getdata</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/272423#716056</link>
      <author>Dave Hathaway</author>
      <description>Sherryl,&lt;br&gt;
&lt;br&gt;
Thank you very much for your suggestions.  As a real-time acquisition program, I am concerned about the throughput of all this stuff.  But, ultimately, we'll be grabbing &quot;only&quot; 200 samples per second.  The processing of those samples occurs at minute intervals, and more hourly.&lt;br&gt;
&lt;br&gt;
The use of TimerFcn and SamplesAcquiredFcn is a result of neither one working for me.  Now that I am getting sustained data sampled, I'll get rid of the SamplesAcquiredFcn.&lt;br&gt;
&lt;br&gt;
One concern that I have is that the program should get what data is acquired at the minute boundary, rather than waiting for 60*200 samples to be obtained.  But doesn't&lt;br&gt;
&lt;br&gt;
set(ai, 'SampleRate', 200);&lt;br&gt;
set(ai, 'SamplesPerTrigger', 12000);&lt;br&gt;
&lt;br&gt;
mean that I won't get a SamplesAvailable &amp;gt; 0 until I have 12000 samples, even if it takes 61 or 62 seconds?&lt;br&gt;
&lt;br&gt;
I guess this issue is outside the topic of this thread, but please know that I have appreciated your help and advice.&lt;br&gt;
&lt;br&gt;
Dave Hathaway</description>
    </item>
    <item>
      <pubDate>Fri, 12 Feb 2010 12:43:05 -0500</pubDate>
      <title>Re: DAQ SamplesAvailable never &gt;0 after getdata</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/272423#717136</link>
      <author>Sherryl Radbil</author>
      <description>Hi Dave,&lt;br&gt;
Glad to have helped. Please see this page about real time and Data Acquisition Toolbox&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/support/solutions/en/data/1-17G8J/?product=DA&amp;solution=1-17G8J&quot;&gt;http://www.mathworks.com/support/solutions/en/data/1-17G8J/?product=DA&amp;solution=1-17G8J&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Regarding:&lt;br&gt;
&amp;gt; set(ai, 'SampleRate', 200);&lt;br&gt;
&amp;gt; set(ai, 'SamplesPerTrigger', 12000);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; mean that I won't get a SamplesAvailable &amp;gt; 0 until I have 12000 samples, even if it takes 61 or 62 seconds?&lt;br&gt;
&lt;br&gt;
SamplesPerTrigger controls when the acquisition stops and not when the data is available.&lt;br&gt;
If you start and trigger the acquisition shown above then pause 1 second and then execute:&lt;br&gt;
&lt;br&gt;
ai.SamplesAvailable&lt;br&gt;
&lt;br&gt;
you should see close to 200. It may not be exactly 200 because it will depend on what size blocks are being transferred between the adaptor and the engine (see ai.BufferingConfig, first number returned is the block size) &lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/daq/bufferingconfig.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/daq/bufferingconfig.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
All the best,&lt;br&gt;
Sherryl</description>
    </item>
  </channel>
</rss>

