LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/Consumer: program freezing up when outputting data from the consumer loop

Solved!
Go to solution

Hi, guys, I'm new at LV.  I have an application where I have a consumer loop controlling a dyno while gathering torque & speed info in the consumer loop.  I found that I ended up having to exit the consumer while loop when I need to output the torque & speed data to TDMS file.  The unforeseen consequence is that I lose control of the dyno at the same time. 

 

I have put together a generic program with random number to generate data.  When I click on "Generate," I can see the array gets populated, but the program freezes up.  I would like to click on "Generate," and output the data, but, at the same time, continue the consumer loop.

0 Kudos
Message 1 of 3
(220 Views)
Solution
Accepted by topic author GusTTShowbiz

Your consumer loop stops when it dequeues generate, but the producer loop doesn't. So the outer while loop doesn't iterate because the producer loop is still executing.

0 Kudos
Message 2 of 3
(190 Views)
Solution
Accepted by topic author GusTTShowbiz

Your "producer" loop at the top only ever terminates when you press the "stop 4" button.  Because of this, the outer loop that contains almost everything can never iterate, because it only iterates when everything inside it has completed execution.

 

I would recommend:

  • Get rid of your outer loop completely
  • Move your array control inside the loop so it updates each loop:
    Kyle97330_0-1724273629893.png
  • Put the code that appends to the array in the "Generate" case so it only adds to the array when you click Generate
  • Strongly consider removing the "Main" case and the enqueueing of it completely, as your code should work fine just waiting for the Dequeue node to either get a "Generate" or "Close" message, there's no need to constantly spin the bottom loop with nothing to do.

 

Since this is just a "demo" VI, and not your real code, some of this might not apply directly to it, but you'd need to get more specific if that's the case.

 

Also a general note that you have 2 stacked terminals on your bottom loop, that's not a good thing:

Kyle97330_1-1724273899602.png

 

0 Kudos
Message 3 of 3
(183 Views)