LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to transfer data between loops?

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

0 Kudos
Message 1 of 9
(11,431 Views)

A wire is always the best way if the loops are not parallel. Use Queues or Notifiers to avoid race conditions

0 Kudos
Message 2 of 9
(11,429 Views)
0 Kudos
Message 3 of 9
(11,420 Views)

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 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 9
(11,394 Views)

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

0 Kudos
Message 5 of 9
(11,383 Views)

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.

0 Kudos
Message 6 of 9
(11,320 Views)

@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.

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 9
(11,312 Views)

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.

0 Kudos
Message 8 of 9
(11,298 Views)

@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.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 9
(11,290 Views)