12-10-2012 12:48 PM - edited 12-10-2012 12:50 PM
ive stuck on a very simple data flow problem here, I'd like to pass data being enqueue in the subvi and dequeue in the main vi consumer loop. Ive attached the vi, since im already stuck on this problem, i was hoping i could learn a few things, specially implementing action engine in this situation 🙂
thanks.
Solved! Go to Solution.
12-10-2012 01:23 PM - edited 12-10-2012 01:24 PM
Your subVI doesn't make any sense since your loop will always exit after the first iteration and you always initialize your counter to 0 every time you execute it. That is one issue.
Your code also suffers from multiple places that are dequeueing data from the queue. You will get undeterministic behavior since you don't know which dequeue will get the data first. Generally for a producer/consumer architecture using queues one or more loops loops should be enqueueing data to the queue. One and only one loop should be dequeueing data. These loops shuold run in parallel to each other. In your code you will only run your subVI whenever you press the start button and as stated you will always post a value of 1 to the queue. What you would need to do is have your subVI run independently once it is started. Use the "Start Asychronous CAll" to start your subVI when the Start button is presed and then let it simply run. Have it post the counter to the queue. Your lower loop in the main VI should dequeue the values and display them. You do not need the Wait in that lower loop since that is the purpose of the dequeue. That loop will be idle if there is no data present and will only run when data is in the queue.
In the upper loop of your main VI remove the dequeue and enqueue. You don't need them since the subVI is all that is needed to post the data to the queue.
Try this:
12-10-2012 02:13 PM - edited 12-10-2012 02:16 PM
Thankyou so much, worked like a charm. and thanks for pointing out my mistakes, my subvi was indeed a blunder.
I just have one more question, what would be the best way to stop the subvi ?
should I bundle the numeric counter with enum carrying stop state in subvi, than use user generated event in main, and settle for stop vi-button event ? would that be a good choice or there is any better, more simpler way?
12-10-2012 03:38 PM
As written the subVI will stop when the queue gets destroyed. If you needed to stop it for other reasons you would need to pass it a stop. There are several ways this can be done. One of the most basic would be to use a functional global/action engine and check this condition each iteration. You could also use a notofier. Again, checking if the stop condition has been met.