10-15-2012 04:05 AM
How can multiple vis share data input from a DAQ simutaneously?
Recently I am building a EMG measurement platform and somehow DAQ data need to be shared by several vis at the same time.
Are there any ideas?
10-15-2012 04:40 AM - edited 10-15-2012 04:52 AM
How many VIs do you have? Are all the vis running parallel?
How are these vis called? Are they all sub vis called inside the same main VI? Are they all running inside the same while loop or in different loops?
The best way is to use Queues. If you have the vis running at different rates and from different locations, use multiple Queues. Create a Queue ref for each vi, enqueue the data into the queues from the DAQ, dequeue in each sub vi, and process
if all the vis are inside the same Main vi and if they all run at the same rate, then use one queue, enqueue from DAQ and dequeue in the Main VI
10-15-2012 05:20 AM
I need to run 3 VIs parallel.
10-15-2012 05:21 AM
They are running in the same project but independently.
10-15-2012 07:08 AM
Use a single loop to acquire your data. You can then use separate queues to send the data to the other VIs. This is a form of the Producer/Consumer Architecture.
10-15-2012 02:27 PM
If you may need to add/delete tasks that will need th edata you may want to consider a publich/subscribe pattern. Basically your DAQ task will post a message to a single queue. The process listening on this queue (message broker) will determine if there are other processes registered to receive this message. When a device registers for a message it provides a queue to receive it on. The message broker will then post the message to all interested processes. The nice thing about this pattern is that you have dedicated code to handle broadcasting the message and it is very easy at run time to change the number of processes that get the message. The DAQ task will always send the message and will not care how many processes are listening.
10-16-2012 12:06 AM
Thank you guys. The producer/consumer pattern is good.
However, if all 3 Vis are placed as subVi in a big one, I will have to run them all everytime. Sometime I don't need to run all 3 programs, maybe only 2.
I am looking for something resembling the global variable of a project, a buffer that can be shared by multiple Vis. But the global variable does not support two dimension arrays or dynamic data.
Is there any substitute for that?
10-16-2012 01:03 AM
I provided an architecture that would work for you in the above post. It will require a but of extra work to create the message broker and the mechanisms to publish your messages and subscribe to them but this architecture is flexible and will support varying number of tasks. You can even change the number of tasks at at runtime.
10-16-2012 01:19 AM
@bdtofu wrote:
Thank you guys. The producer/consumer pattern is good.
However, if all 3 Vis are placed as subVi in a big one, I will have to run them all everytime. Sometime I don't need to run all 3 programs, maybe only 2.
I am looking for something resembling the global variable of a project, a buffer that can be shared by multiple Vis. But the global variable does not support two dimension arrays or dynamic data.
Is there any substitute for that?
There is no need for producer/consumer. It is just a "popcorn-machine" that "rattles away" with everything you enqueue, that is usually stuff for handling sporadic events and not continous processing.
You can use the already existing device buffer by handling the DAQ buffer pointers. This thread could give you some hints:
Br,
/Roger
10-16-2012 01:53 AM
When you want to acquire the data and share the data to multiple loops, 'Queue' is not a option; instead 'Circular Buffer' is the option for you.
The 'Circular Buffer' data structure is used to share the data between multiple loops but with same synchronized manner.
Like 'Queue' (FIFO, LIFO, FILO), circular buffer also can be clasified diffrently.
You can use 'LV2G' as a 'Circular Buffer' and you can customize also.
Below are the links talk about Circular buffer.
http://www.ni.com/white-paper/7188/en
https://decibel.ni.com/content/docs/DOC-14554
How to use array as a circular buffer?
https://decibel.ni.com/content/docs/DOC-3414
Regards,
Yogesh Redemptor