Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sequence of execution of DAQmxRegisterEveryNSamplesEvent

140 views
Skip to first unread message

Chapashop

unread,
Jun 27, 2008, 1:40:15 PM6/27/08
to
I have a working app that uses VB6 with NIDAQmx. I found NI code samples that are working for me however I am not sure I understand in what order they are being executed.  I am writing up a manual that explains my code.  My question is when does my DAQmxReadBinaryI16 function execute.  I was
thinking that EveryNSamplesEventHandler fires after my acq has
completed.  But I don't see how that would work.  I place my own code
after my Read function and everything is working but I just don't
understand when my Read function actually happens.
create taskconfigure analog channelsstart taskwait for EveryNSamplesEventHandler to executeAlso do I need to use the DAQmxGetTaskNumChans before my READ function.  Like I said I grabbed this from a sample but as I  closely exam this I already know the value of numchannels so I don't think I need this function.I guess while I am asking I have the same question about the DAQmxGetTaskNumChans function when I am configuring my channels.  It returns the number of samples which I also know what I am expecting.thanks for any help,Public Function EveryNSamplesEventHandler(ByVal taskhandle As Long, ByVal eventType As Long, ByVal numSamples As Long, ByVal callbackData As Long) As Long    Dim numRead As Long    Dim acqtype As Integer         DAQmxErrChk (DAQmxGetTaskNumChans(taskhandle, numChannels))    DAQmxErrChk (DAQmxReadBinaryI16(taskhandle, numSamples, 10, DAQmx_Val_GroupByScanNumber, dataBuffer(0), numChannels * numSamples, numRead, ByVal 0))   

J_Thomas

unread,
Jun 30, 2008, 1:10:14 PM6/30/08
to
Hi Chapashop,


The DAQmxRegisterEveryNSamplesEvent registers a callback
function to receive an event when the specified number of samples is written
from the device to the buffer or from the buffer to the device.  (see the NI-DAQmx C Reference Help for more
information about this function).  So if
I have an analog input task, and I specify 1000 samples in the DAQmxRegisterEveryNSamplesEvent
function, and I create a callback function that performs a digital read, my
digital read function will be fired as soon as 1000 samples of the analog input
task have been transferred to the buffer.


In your case your EveryNSamplesEventHandler
function (which has your
DAQmxReadBinary16 function), will be fired as soon as the number of samples you
specified when you registered the event have been transferred to the buffer.


As
far as your other questions about the DAQmxGetTaskNumChans function, I do not
believe you need to use this function if you already know the number of samples
or channels that you will be using.  One
of the advantages for using it, however, are if you ever need to changed the
number of samples or channels in your code, you will only need to change this
information in one place, instead of two. 
It helps to make the code more modular and easier to maintain.


Hope
this helps.

0 new messages