Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

sequence of execution of DAQmxRegisterEveryNSamplesEvent

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 task
configure analog channels
start task
wait for EveryNSamplesEventHandler to execute


Also 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))
   
0 Kudos
Message 1 of 3
(6,948 Views)

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.

Jared T.
0 Kudos
Message 2 of 3
(6,922 Views)
Jared,

Thanks for the information.  It is exactly the information I needed to clarify what I was doing.

Prior to using DAQmx functions I was using VB6 with Measurement Studio with legacy DAQ devices so alot of things were done for me using activeX controls.

About 20 years ago or so when I using old GW-BASIC and different DAQ hardware the methods were somewhat different and a Read command started the acquisition, if my memory serves me right.  But it makes sense what you are saying and that is what I suspected.  I had read the documentation but I did not understand it completely but for the most part I do and all my code is working the way I need it to.  And thanks also for answering the other questions.

David
0 Kudos
Message 3 of 3
(6,918 Views)