1

In a moment of uninformed arrogance, I decided that my new data acquisition computer is going to be an x64 running win7. I have matlab 2012a running on the computer and a NI PCIe6363 card doing the data acq. My question is about the new daq.Session interface and how to collect data in the background(a critical component of my experiments).

I am including some example code. I will try and explain what I thought the code is expected to do. And what actually happens....

Code:

function runSessionDAQ
s = daq.createSession ('ni'); s.addAnalogInputChannel('Dev1', 0, 'Voltage');
s.IsContinuous = true; s.Rate = 10000;
timeDuration = 5;
s.NotifyWhenDataAvailableExceeds = s.Rate*timeDuration-1; %trigger 'DataAvailable' before the last sample is collected
lh = s.addlistener('DataAvailable', @(src,events)collectAndSaveData(src,events));

function collectAndSaveData(src,event)
    fprintf('here\n');
    t = event.TimeStamps; data = event.Data;
    save('C:\Users\ephys-data\Desktop\data.mat','t','data');
end

tic;
startT = toc;
stopT = startT+timeDuration;
stop = false;
s.startBackground();
while ~stop
    if toc>stopT;
        stop = true;
        s.ScansAcquired
        s.stop();
        fprintf('stopping....\n');
    else
        if s.ScansAcquired == 0
%             keyboard
        end
        fprintf('continuing...\n')
    end
    WaitSecs(0.5);
end
delete(lh);
end

Expected function: Continuously log data from the card for about 5 seconds. Just before the last few data points are scanned, save the data in an appropriate location. Then stop the acquisition.

Actual result:

>>runSessionDAQ
continuing...
continuing...
continuing...
continuing...
continuing...
continuing...
continuing...
continuing...
continuing...
continuing...

ans =

                0

stopping....

No data is stored in the appropriate location. Actually claims that number of ScansAcquired is zero. And just stops.

What is happening? How should I design my listener?

=========

\begin{rant}

I can't believe how poorly documented the matlab website is for the session based DAQ. And no timed Digital I/O? Sheesh!

\end{rant}

=========

-bas

bas
  • 209
  • 2
  • 10
  • Did you try modifying the callback definition to `lh = s.addlistener('DataAvailable', @collectAndSaveData);`? – H.Muster Oct 11 '12 at 20:18
  • the call back is never called. as i understand, 'DataAvailable' event is triggered as soon as 'NotifyWhenDataAvailableExceeds' value is reached. In my case, it should definitely be reached before the time duration as i am requesting fewer data points. To the best of my knowledge, the callback function is never called. – bas Oct 11 '12 at 21:31
  • And modifying the call back as you mentioned did not help. – bas Oct 11 '12 at 21:43
  • 1
    Okay, the problem seems to be with my use of WaitSecs. I used pause and the program works as intended....weird – bas Oct 11 '12 at 21:53
  • Can there be an alternative way to get the data without the need to save to a mat file? – bla Dec 27 '12 at 01:39
  • Have you looked at simulink? It is more built for intuitive connection to hardware. – EngrStudent Mar 20 '14 at 22:32
  • 1
    So what was `WaitSecs`exactly doing? For saving money on Matlab licenses you also might want to check pylibnidaqmx. @natan He could use a global variable or store it in the src if possible. – NoDataDumpNoContribution May 26 '14 at 14:13

0 Answers0