07-16-2010 05:11 AM
Hi, whats the best way to transfer data between loops(state machines, regular while loop etc) in labview. For so many years ive been using local variables but these can cause race conditions. Anyone advise?
Stu
07-16-2010 05:18 AM
A wire is always the best way if the loops are not parallel. Use Queues or Notifiers to avoid race conditions
07-16-2010 05:28 AM
07-16-2010 07:43 AM
A properly implemented Action Engine is in my opinion the easiest code construct to learn that will allow inter-thread (across PC's as well!) communication.
The Nugget linked in the hyperlink above was written a resource to the community to answer your question.
I hope it helps.
Ben
07-16-2010 08:01 AM
It depends one the structure of the loops and how they need to exchange data (unidirectional, bidirectional, broadcasting).
The simple case of one loop passing data to the other loop: producer/consumer design pattern using a queue
If the structure already contains an event structure: User Events
The way I code is documented in my community nugget on events
I often mix this with producer/consumer.
Felix
07-20-2010 11:56 AM
Hi guys thanks for the replies. think im going to use shared variables with compact rio. It seems to fit my criterea and due to to having 300 inputs e.g. thermocouples etc.but i do like those action engines, not sure if there scaleable, as in 300 different inputs and outputs.
07-20-2010 12:06 PM
@stu22 wrote:
Hi guys thanks for the replies. think im going to use shared variables with compact rio. \
Beware, shared variables is like a global variabel. You can have race conditions just as well. Why not use a queue?
If you are gathering thermocouple data, and then processing the data, you should be using a producer-consumer architecture with a queue to pass data from the producer to the consumer. That way you won't miss any data.
07-20-2010 02:33 PM
Hi, the only thing that bothers me about that. Is the size of the queue i will generate and how much time it will take to pass all the data.
07-20-2010 02:52 PM
@stu22 wrote:
Hi, the only thing that bothers me about that. Is the size of the queue i will generate and how much time it will take to pass all the data.
300 thermocouples is a lot of data. Whatever method you choose will not be a piece of cake. Queues are limited only by the size of your computer's memory. In order to keep track of which data belongs to which thermocouple, you may have to bundle the data with a thermocouple ID, and send the cluster to the queue. Or you could read the devices in exact order and build an array so that device 1 is the first element, and so on. Then you could send the array to the queue.