LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

why the producer comsumer loop don't transfer '0'?

Solved!
Go to solution

I have a producer loop produce '1' and '0', then I try to transfer '0' or '1' produced to consumer loop. Initially I get '0' for the consumer, but once the '1' is tansfered to it, the '1' will always be in consumer loop, '0' will not be transfered, even the producer do produce a '0'. How come it's like this?Capture.PNG

0 Kudos
Message 1 of 4
(2,441 Views)
Solution
Accepted by topic author 100148X

Are you hitting the "stop3" button after receiving a "1"? If not, you'll be stuck in the while loop (inside the 1 case) and your queue will not be handled until the loop terminates.

0 Kudos
Message 2 of 4
(2,436 Views)

I see you are reading the boolean value from a global variable and then you are converting that into an integer and then you are sending the value to the consumer loop and reading it and doing some operation.

 

My question is: Why don't you wire the Global variable directly to the 2nd loop case structure (consumer loop) and remove the producer loop, this is rubed code definitely. Also in your code you are running the Producer loop without time delay with a case structure that is also wired by a constant so you will eat the CPU by running 2 very fast loops without giving handle to the OS.

 

Why you always run into the 1 case always: Assuming that you do not have anything in the case 0 of the consumer loop Here is the story for you.

 

You are giving 0 to the consumer constantly and since the case 0 doesn't have anything the speed matches the Producer but once you enter into the 1 you have some code there you are calling the driver and certainly it takes time than the Producer. Since you are continuously running the producer all the 1s are queued up and that is the reason even after changing the value you are running into the same 1 case in the consumer.

 

Suggestion: Go for  a design pattern that matches your requirement.

 

Edit: Oops I didn't see the while loop inside. 

-----

The best solution is the one you find it by yourself
0 Kudos
Message 3 of 4
(2,432 Views)

Is anything happening in the "0" case?

 

I would recommend initializing and closing your instrument outside of the consumer loop.  Then remove the innermost while loop.  Then whenever you get a 1, you send the command and check the queue again.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(2,388 Views)