Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use RegisterEveryNSamplesEvent?

I am upgrading Traditional to Legacy, one of the features I am trying to convert is half_Ready which used to tell the Acq Thread that buffer has the samples and ready to be read.... I understand RegisterSamplesEvent will create an event that triggers a function to go read the buffer. But I am having problem making it fit into the flow chart.....Please take a quick look, I have the following;

 

While Thread is ON

 {

     ------- GetDAQData( ...) ;

     ------- etc ........

      int GetDAQData (int *Buffer)

         {

             // Here I used to check flag if Buffer is ready to read using Half_ready

              if(Half-Ready is good)         // How do I replace this concept here ??? - I know half buffers don't exist anymore

                {

                    DAQmxReadBinary16( ...8 chs ...)

                    DAQMxReadCounter ( ... PFI7 ...)

                    DAQmxReadCounter( .... PFI7..)

                    .......//etc

                  }

           }  //end GetDAQData function

   .......

   .......etc

 

} //end Thread

 

So, where do RegisterEveryNSamplesEvent and its function handler will fit in this picture???

 

Thanks

          

0 Kudos
Message 1 of 17
(6,504 Views)
Sorry, I forgot to say that I don't have to use EveryNSamplesEvent if there is anything like a property or a flag that tells me Ok the Buffer has the samples and is ready to be read, then I can go and read it.....It used to be Half_Ready, is there anyhting equivalent to this in NiDAQmx?
0 Kudos
Message 2 of 17
(6,502 Views)

I too would find the answer to this question most useful. Thanks!

 

0 Kudos
Message 3 of 17
(6,465 Views)

Hello NewBe,

 

There is a RegisterEveryNSamplesEvent function in DAQmx.  It is called DAQmxRegisterEveryNSamplesEvent.  I'm not very savvy when it comes to programming in Visual Basic, and I couldn't find an example in Visual Basic, but I did find an example in LabVIEW that uses the Register for Events property node in a way that is similar to how you intend to use it.  While I research how to apply this function in Visual Basic, I will leave you with the program flow in LabVIEW as you may find it helpful. The LabVIEW code sequence is below:

 

1. Create virtual channel for analog input.

2. Configure channel timing with the DAQmx Timing VI.

3. Use the Register Events property node for EveryNSamplesAcqIntoBuffer

4. Start task

5. While loop with an event structure inside.  The event structure has cases for the following events:

    a.  Every N Samples Acq Into Buffer

    b.  Stop

    c.  Task is done

    d.  Timeout.

 

The image attached to this post is the block diagram in LabVIEW that illustrates the program flow if more detail is needed.  In the meantime, I will continue my efforts to find an applicable example in Visual Basic.

 

Best wishes,

Wallace F.

National Instruments
Applications Engineer
0 Kudos
Message 4 of 17
(6,430 Views)

Thanks for your response. My application is actually Visual C++, I am still not clear on the flow of the code starting at your step 5. 

1 - First problem I have is that I am unable to make the call back function a data member of my class, and the one example I found in "Measure Voltage" shows the function as a static prototype- I need this

     function to have access to other data members.......

 

2- Second problem, in summary, within the Call back function, I will read Analog and counter tasks knowing at this point the buffer is ready to be read, I will process that data and need to stuff it into a buffer

    but, I need pass this Data buffer along with couple of other parameters into the rest of the program.... How can I do this when I can't chnage the arguments and parameters of the NI Call back function ?

 

 This pseudo code is how the traditional worked for me:

 

 While (1)

 {

     ......

     int ReturnedNum = GetNIBrdData(MyBuffer);

     ......

}

 

int GetNIBrdData(int *MyBuffer)

 {

    if(Half_Ready) { //if Buffer is ready to be read

      DAQmxReadBinary16( ....analog chs)

      DAQmxReadCounterU32( PFI7...PFI4...)

 

       //Process Data and stuff in in the buffer

      MyBuffer[i] = processeddata;

     }

return  ReturnedNum;

}

 

So, how do I get to read "MyBuffer" if this was processed inside Call back function, and how do I make it a data class member?

 

Thanks

0 Kudos
Message 5 of 17
(6,419 Views)

This could be a very useful thread!

 

I have a supplementary question about multiple device transfers. The program is to collect continuously 256 (say) channels of analog data using 4x M-series boards that are capable of digitizing at least 64 channels. The boards are connected with PXI. Presumably, four tasks need to be created, one for each board, specifying the channels 1-64, input range, etc. Because the digitization needs to be synchronized (if not synchronous), some kind of triggering needs to be specified. Also, the four tasks use a common (PXI/backplane) clock.

 

My questions are:

 

1) Do the 4 tasks share a single callback, or is a separate one created for each? (If the latter, this implies four bits of idenitical code, most likely calling a common procedure.)

 

2) Are the callbacks called in the same order as the tasks were created? It is important to know where the data came from and where to put it in the program's own data buffer.

 

3) Is there any code (preferably in C) that demonstrates this technique? I imagine other people must do the same kind of multiple-board data collection.

 

Thanks!

 

Francis

 

0 Kudos
Message 6 of 17
(6,406 Views)

By the way, NI_2008 is NewBe as well.

 

I answered my first problem by declaring my function as a static data member and then using a Class instnace to access no-static data  members of my class........... the solution for this problem will do for now........

 

I would sill like the answer/Feedback for my second problem of how to pass data back and forth, for example the buffer that I intend to read from EveryNSamples function...... I know I could declare a buffer as a data member and use it, but I would have to break the code flow that I have....I just wanna make sure its the right way of doing it and I am not missing something...... I would think there should be a way of passing data back and forth from the function somehow... I mean ppl can't just read the data and process it in that function and stop right there, it would make sense that the data has to be passed to the rest of the program after that point..... hopefully you understand what I am trying to accomplish here....

 

 

Thanks

0 Kudos
Message 7 of 17
(6,382 Views)
Disgusting...I take that back, I can't even get the RegisterEvent function to work in MFC.....
0 Kudos
Message 8 of 17
(6,370 Views)

NewBe/NI_2008,

 

There is an example that uses the RegisterEveryNSamplesEvents function call in ANSI C.  If you are using Windows XP, it can be found at the following location in your directory structure:

 C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Events\Every N Samples

 

I was able to run the example in VS2005, and it seemed to work just fine. The source code is documented so that it indicates the different functional areas of the program. For your convenience, I have also attached the source code as a word document to this post.

 

Best wishes,

Wallace F.

 

National Instruments
Applications Engineer
0 Kudos
Message 9 of 17
(6,351 Views)

Hi, 

I think you are missing my point. The function in the example is not declared as a member function, but once I do declare it as a data member of my class in my MFC application, I lose access to other data members... I wonder if this is the same implementation in visual C++.

0 Kudos
Message 10 of 17
(6,343 Views)