LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer consumer pattern with third loop

Solved!
Go to solution

Hello All and thanks for looking a this.

 

I have a problem I've been thinking about for a while now about running a third loop in a producer consumer (with events) design pattern.

I'm using this type of pattern for a user interface and am happy with the way it works. However if I want to add a continuis loop to the pattern to run a test for example how do i control the loop?

In my example (see attached) i have use a local variable to both run (or stop) the test and the same to close the application.

 

I'm not sure why but this feels wrong to me. Is there a better way?

 

Thanks in advance

 

Chuck

0 Kudos
Message 1 of 7
(4,107 Views)

Think about what you want the Producer and Consumer loops to do.  You have three buttons -- Run Test, Test (a button that bears the label "Stop"), and a Stop Button.  

 

First question -- what is the difference between "Run Test" and "Test"?  Does one of these (I'm presuming "Test") initialize stuff so that a subsequent press of "Run Test" causes tests to be run continuously 8 times/second until "Run Test" is turned off?

 

Second question -- have you thought about what happens (or, better, what you want to happen) if you push Run Test before pushing Test?

 

It sounds like you have a system that can exist in several "states" -- an "Idle" state, where it initially starts, before it has been given any Commands, a "Ready to Test" state after it has been set up to run a test (I'm assuming this occurs when the Test button is pressed), and a "Testing" state where it does a test (and, maybe does another test 125 msec later).

 

The Producer loop can be considered to give one of four "commands" -- Setup (when Test pushed), Start Run (when Run Test becomes True), Stop Run (when Run Test becomes False), and Quit (when Stop is pushed).  It can send it to a single Consumer loop, provided that the Consumer loop also knows its "state".  For example, in the Idle State, the only commands that should be processed are Setup and Quit (since you can't do Start Run or Stop Run before you initialize the tests).

 

So your Consumer loop remains a single loop, but its innards get a bit more complicated (as it needs to remember its state).  Not too difficult ...

 

Bob Schor

Message 2 of 7
(4,066 Views)

Thanks for looking at this

 

The Test loop is used to continually test something (Say a battery voltage) The problem with the consumer loop is it only runs when it receive a message from the producer loops event.

I can sort of see what you mean but how would you get the messages into the consumer loop

 

Chuck

0 Kudos
Message 3 of 7
(4,053 Views)

Can you supply an illustration to show me what you mean?

0 Kudos
Message 4 of 7
(4,043 Views)

Not near a PC with LabVIEW.  Be back Tuesday.

 

BS

0 Kudos
Message 5 of 7
(3,999 Views)
Solution
Accepted by topic author Nickleback

Nickleback wrote:

The problem with the consumer loop is it only runs when it receive a message from the producer loops event.


Nothing says you can't have a consumer loop enqueue states to itself.  Of course, this turns more into a Queued State Machine with the ability for another loop to enqueue states.



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
Message 6 of 7
(3,971 Views)

Ok thanks

0 Kudos
Message 7 of 7
(3,909 Views)