LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

need help with producer/consumer structure

hi,

i am trying to learn how the producer/consumer structure works and i am currently stuck understanding the queue fundamentals.

i am trying to create 2 loop. one is to control using events and one is the consuming loop.

i am trying to get the 2nd loop to stop when i click on "STOP" but i am not able to do so. can someone take a look at my example and help me out.

thank you.

 

Message Edited by krispiekream on 01-12-2009 05:03 PM
Best regards,
Krispiekream
Download All
0 Kudos
Message 1 of 19
(4,843 Views)

Just an idea to work with. Since you are using an event structure you probably have a stop event. I would use the event structure to determine what state the consumer loop uses next. Since you can queue a cluster you could send the correct state to the queue, dequeue in the consumer loop, unbundle by name and set the state of the state machine. Just select the proper type def enum constant in each event of the event structure and queue it up.

Hope this makes sense and helps.

 

Happy coding.

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 2 of 19
(4,830 Views)

The inner while loop is basically a no-no, but if you want it I would go for a notifier to transer the 'stop' state.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 3 of 19
(4,808 Views)

You haven't enqueued anything so the Dequeue Element in your consumer loop is waiting for an event that never happens.  The while loop that is supposed to stop when the Stop boolean is pressed doesn't even start.  I've solved it by wiring a constant to your Dequeue Element, but you'll need to handle this however is appropriate for your application.  Run your code with Highlite Execution turned on and you'll see what I mean.

 

Message Edited by jcarmody on 01-13-2009 05:05 AM
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 4 of 19
(4,793 Views)

Your approach lacks of some important things. First of all, Producer Consumer State Machine.vi is a complete mess and will not work.

 Producer Consumer State Machine demo.vi is the one you attached as screenshot as well; this one is better, but still not in a good shape.

 

So here my suggestion:

1.) Split Data from Commands. Your queue passes all data in your application. This is not good. In general, use commands to inform the consumer "that something happened". It is suggested to use a typified enum for this. If you have to pass data using the queue as well, transfer only the needed part as data in form of a variant datatype. Use the command to extract the correct datatyp from the variant in your consumer. See attached screenshot.

2.) Never use While Loops in the consumer. This is a guideline and may not fit all requisitions, but it keeps you from running into pitfalls.

3.) Define a special Shutdownprocedure. This can be e.g. sending "Stop" command from producer and then shutting down everything in your consumer. Please note that it might be useful to release the queue after leaving the consumer.\

4.) Do not use local variables to transfer data between producer and consumer. Get used to transfer data using the queue (screenshot), or functional globals (also known as action engine). Variables in general do no good to programming LabVIEW (with certain exceptions of course!).

 

 

 

Those are the most important suggestions which came into my mind right now. 

 

hope this helps,

Norbert 

Message Edited by Norbert B on 01-13-2009 06:24 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 5 of 19
(4,776 Views)

i learn faster when looking at diagrams.

can you fix the Producer Consumer State Machine demo.vi and let me she what it can do to be fix?

thanks

 

Best regards,
Krispiekream
0 Kudos
Message 6 of 19
(4,752 Views)

The Producer/Consumer Design Pattern (Events) (File_New_From Template_Frameworks_Design Patterns).  The only thing I changed is that the template doesn't feed the dequeued element into the handler.

 

Message Edited by jcarmody on 01-13-2009 11:58 AM
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 7 of 19
(4,737 Views)

hmm, it seems like i am not getting it.

how would i stop the button loop without using locals?

i only want the bottom loop to end when i call for it, otherwise, it will go on forever.

 

Best regards,
Krispiekream
0 Kudos
Message 8 of 19
(4,724 Views)

The bottom loop will close because the top loop releases the queue reference.  When this happens the Dequeue Element in the bottom loop will send an error into the condition terminal, causing it to stop.  Turn Highlite Execution on and watch it happen.

 

Jim

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 9 of 19
(4,715 Views)

i am watching the highlights.

the bottom loop closes but I have not yet click the stop bottom

it should only stop the bottom loop when the button is clicked on?

 

Best regards,
Krispiekream
0 Kudos
Message 10 of 19
(4,712 Views)