LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer/consumer loops with notification

@Billko -- if a LabVIEW 2021 user uses the "From Template" code to create a Producer/Consumer Design Pattern for either Data or Events, the Producer destroys the Queue, leaving the Consumer to have to "error out".  If one is designing a "Queued State Machine" (or a Queued Message Handler) using Producer/Consumer logic, and the Producer responds to a condition that means "Time for an orderly exit" (such as responding to a push of the Stop button), then the Producer should be able to safely exit (without "destroying" anything after it sends its final message, "That's All, Folks", to the Consumer, which can execute whatever "cleanup" code it needs for exits, and when it exits, it can release the Queue.  No need to generate a spurious Error by having the Producer prematurely release the Queue.

 

There may be other "example code" where NI shows this "Producer safely exits, telling Consumer to exit also" method, but it hasn't migrated to the New ... templates.

 

Bob Schor

0 Kudos
Message 11 of 27
(1,319 Views)

@Bob_Schor wrote:

@Billko -- if a LabVIEW 2021 user uses the "From Template" code to create a Producer/Consumer Design Pattern for either Data or Events, the Producer destroys the Queue, leaving the Consumer to have to "error out".  If one is designing a "Queued State Machine" (or a Queued Message Handler) using Producer/Consumer logic, and the Producer responds to a condition that means "Time for an orderly exit" (such as responding to a push of the Stop button), then the Producer should be able to safely exit (without "destroying" anything after it sends its final message, "That's All, Folks", to the Consumer, which can execute whatever "cleanup" code it needs for exits, and when it exits, it can release the Queue.  No need to generate a spurious Error by having the Producer prematurely release the Queue.

 

There may be other "example code" where NI shows this "Producer safely exits, telling Consumer to exit also" method, but it hasn't migrated to the New ... templates.

 

Bob Schor


I agree completely.  Graceful exit is always the way to go.  I always send an explicit Exit command.  And just to make sure, all my error wires coming out of the loops all get merged before destroying anything, guaranteeing that all the loops have stopped processing.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 12 of 27
(1,307 Views)

hi,

I Came with new code. now this Stop button is working fine but the problem is the consumer while loop is not running continuously it is running only for one iteration then again it needs to click connect button. So i need to make it like when i click connect button then the consumer while loop should run continuously. can you give me suggestions?  

Thank you

0 Kudos
Message 13 of 27
(1,277 Views)

I can't open the code, but usually you simply use the Timeout of the consumer queue to perform some idle action. If you want to activeate some "measurement mode" you can set a mode parameter and use said timeout (set it low while in that mode) to keep measuring. 

You can also use the anti-pattern of queueing up a new measurement as one is done. This can lead to an ever growing queue and can be dangerous, thus an anti-pattern.

As all tools they can be used if careful.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 14 of 27
(1,270 Views)

I'm attaching the snippet of my code so you can get it. please can you look at it ???

Thank you

0 Kudos
Message 15 of 27
(1,263 Views)

As i thought. Just add a timeout to the Dequeue and check the Timed out-output. If timed out, do Idle action. Oh, and remove the Wait from the consumer.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 16 of 27
(1,243 Views)

Hi yamaeda ,

Still, while loop is not running continuously. can someone help me please i added the timeout also am i doing right? Can someone correct the VI ?? because now im lost

 adding VI as well

 

Thank you in advance 

0 Kudos
Message 17 of 27
(1,212 Views)

Can someone tell me what is wrong in here?? i added timeout as well...

 

thank you 

0 Kudos
Message 18 of 27
(1,187 Views)

Something like this: 

Idle-queue.png

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 19 of 27
(1,165 Views)

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?

Download All
0 Kudos
Message 20 of 27
(1,143 Views)