10-17-2022 07:26 PM
@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
10-17-2022 09:29 PM
@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.
10-19-2022 02:35 AM
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
10-19-2022 03:25 AM
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.
10-19-2022 03:35 AM
I'm attaching the snippet of my code so you can get it. please can you look at it ???
Thank you
10-19-2022 06:12 AM - edited 10-19-2022 06:13 AM
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.
10-19-2022 11:16 AM - edited 10-19-2022 11:16 AM
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
10-20-2022 04:40 AM
Can someone tell me what is wrong in here?? i added timeout as well...
thank you
10-20-2022 09:48 AM
Something like this:
10-20-2022 12:24 PM - edited 10-20-2022 01:03 PM
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?