LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer/consumer loops with notification

There are multiple things "not quite right" with this code, possibly due to a lack of understanding of some of the Fundamentals.  Here are some comments:

  • When I ran your code, I was never able to "see the error".  Not sure what button you pushed in what order to cause it.
  • I believe that the Deeper Thinkers at NI realized that it is a "mistake" to "Enqueue Element At Opposite End".  More recent structures (Asynchronous Channel Wires) do not allow this.  You certainly do not need it!
  • I recommend not putting the Error line in a Shift Register, particularly in Processing Loops.  Once an Error is there, it will always be there unless you clear it!
  • Suppose you have an "Unknown State".  Trace (on paper, or run the code with Highlight Execution, the little light-bulb on the Block Diagram Task Bar between the words "Project" and "Operate") what happens.  One generally puts Error handling at the end of the Loop processing (which is the point I mentioned previously).  Note that if you want to "go to Shutdown" in the Consumer, there is nothing stopping you from simply putting "Shutdown" on the Queue and letting the Queue "spin" one more time.
  • But how do you stop the Producer if the Consumer errors out?  A "Value Signaling" Boolean is clumsy.  Having a "Stop" button on the Front Panel is a good idea, but as you have seen, you can't Value-signal a Stop (or "Escape") if it has the appropriate Latch When Released action.  One thing to try is to create a Global Variable, maybe called "Abort", that is a Boolean, default "False".  Do you see the little hour-glass icon in the upper-left corner of the Event structure?  That's a timer that governs how often (in milliseconds) the Application Activation event, "Timeout" runs.  If 10 times a second the Timeout Event reads the "Abort" Global and simply wires its value to the Stop Indicator of its While Loop, it won't interfere with any processing you are doing, and yet will (quickly) stop the Event Loop if necessary.
  • Instead of setting individual controls to default, you can set all the controls to default (and won't need to enable/disable any of them, probably).  You do this with an Invoke node, not a Property Node.  In addition to the Invoke Node, also drop down a "VI Server Reference" (also on the Application Control palette), which will show up as "This VI".  Wire that to the upper-left input of the Invoke Node, which turns it into a VI "Method".  Right-click the Method, go down to Default Values, and choose "Reinitialize All to Default".

Try making these changes and see how they work.

 

Bob Schor

 

0 Kudos
Message 21 of 27
(1,033 Views)

hi bob, thank you for the suggestions i will do those changes.

  •  The attached VI works fine but the main problem in that VI is the consumer loop (while) is not running continuously. It is running for only one iteration when we click connect button.  this is the main problem.

Can you please tell me what can i do to solve this? because its working with notifier but not with QMH 

 

thank you

 

0 Kudos
Message 22 of 27
(1,018 Views)

Your Consumer Loop starts with a Dequeue.  What if the Queue is empty (because you haven't put anything in it since it processed whatever was originally there, e.g. "Initialize")?  It will wait (patiently, taking no CPU time, so you can be doing other things "in parallel") until there's something in the Queue or it "times out".  Click on the Dequeue function and bring up the detailed Help for Dequeue -- notice the Time Out input (lower left)?  If unwired, it has a default value of -1, meaning "Wait forever" until there's something on the Queue.

 

Your code does exactly what you told it to do.  You should probably use the LabVIEW Help on the other functions in your code to make sure you understand how they work.

 

Bob Schor

0 Kudos
Message 23 of 27
(998 Views)

hi bob,

Thank you.

 

found one example as you said  and  Added some data in Queue. but no improvements at all. can you tell me what is the exact problem beacuse im not that expert 

 

thank you

0 Kudos
Message 24 of 27
(979 Views)

@newmemeber123 wrote:

i converted it in LabVIEW 2018 i think now you can see my previous vi which i was trying. i tried your idea its showing error. can you please check the VI?


You're sending out the case "". In my example i have a default "idle". If you have no ""-case (or default) you'll get the error you see.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 25 of 27
(965 Views)

i made a changes as you said the while loop is running but  now when i press the connect  button from event structure of producer loop it's not working the state of the case is not chnaging. my idea is if i presss connect button from producer loop then the consumer loop should start running with in the connect case and if press the disconnect button then program in disconnect case should execute. 

0 Kudos
Message 26 of 27
(960 Views)

Your Producer Loop IS running. What makes you think it isn't?

 

Within the Block Diagram, turn on Highlight Execution and press Run. You'll see that everything is running in the Producer While Loop & the Consumer While Loop.

Message 27 of 27
(942 Views)