Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Tasks- Analog Input and Analog Output

Hi,

 

I have tried to look through old discussions on this forum to solve my problem, but I haven't been able to find anything.  I'm an intern and don't have that much experience with this sort of programming, so I figure this might be a simple problem that I can't figure out.  I am continuously reading in accelerometer data from three analog input channels, and I want to continuously output that same data to a motor through an analog output channel. I have created two tasks, one for analog input and one for analog output, and used the DAQmxRegisterEveryNSamplesEvent function to register a callback function for each task.  The problem is that it seems like once the program goes into the input function, which it does correctly, it never gets to the output function.  How can I get it to let me output the data it reads in before it reads new data?

 

Sorry if my post is confusing, and I can try to provide more details if necessary.

 

Thanks,

Tim

0 Kudos
Message 1 of 5
(3,543 Views)

Howdy tscalley!

 

Would you please explain how your code is architected or post a screenshot of the block diagram?  Are you reading a single point at a time or multiple points per call of the DAQmx Read VI?  Also, what else is going on in your loop?

 

Regards,

Barron
Applications Engineering
National Instruments
0 Kudos
Message 2 of 5
(3,521 Views)

Hi Barron,

 

Thanks for your reply, and I'll try to answer your questions as best I can.  I'm programming in C++ using Visual Studio 2008, so I don't have a block diagram or VI (that's LabVIEW stuff, right?).  I'm trying to use two CVICallback functions, one to read data from three analog input channels, and the other to output that same data through an analog output channel.  Is it possible to use two Callback functions like this?

 

I have been modifying sample code that came with the software, and I can do the things I want to individually, just not together.  I've attached my code in a WordPad file, but I know it's not the neatest and is going to be confusing, so I understand if it's not possible to find a solution. 

 

Thanks a lot, and let me know if there is any more information I can give.

 

Tim

0 Kudos
Message 3 of 5
(3,518 Views)

I looked over your code and was a bit confused about what was going on.  I'm not sure that callbacks are the correct way to go about your task.  If I was trying to perform a continuous acquisition and generation I would use the producer/consumer architecture.  There should be two threads:

 

1. The producer thread is starts the analog input task and then continuously reads samples and passes them to a queue.

2. The consumer thread retrieves samples from the queue and then passes them to an analog output task.

 

The queue can be created as a circular buffer.  There are probably already libraries available for queue management, but I am not familiar with them.

 

Regards,

Barron
Applications Engineering
National Instruments
0 Kudos
Message 4 of 5
(3,462 Views)

Hi Barron,

 

Thanks for your reply; I appreciate you looking into this so much.  It didn't seem like the way our program was working was the right way to go about it.  We have made some progress using the Synch AIAO example program and modifying it, but I will keep the producer/consumer method in mind too.

 

Thanks,

Tim 

0 Kudos
Message 5 of 5
(3,460 Views)