LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/Consumer Help

I have created this labview code called '2D Fit.VI' without any DAQ hardware that will create a mutlidimensional fit, is it possible to put this VI in a Producer/Consumer format? If so how would I approach it?  The VI's are attached below. 

 

Thanks. 

0 Kudos
Message 1 of 12
(850 Views)

You're using the event structure incorrectly even without a producer/consumer design pattern.  The VI will run the same whether or not the event structure is there.  You first need to change it so there is a seperate case for each button's value change event.  Let's work on this problem before you try producer/consumer.

 

The time out event only fires if no other event happens during the timeout interval.  Since nothing different will happen until a control's value changes you don't seem to need a timeout case so don't use one.  Use shift registers to tranfer data from one iteration to the next.  Put each control inside it's respective case along with the code for that and pass the results out to the indicators, which should be outside the event structure but inside the loop.  You can have them before or after the event structure since the data will be coming from shift registers.

 

We can work on the producer/consumer design pattern after you understand this.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 2 of 12
(819 Views)

@kbbersch wrote:

The VI will run the same whether or not the event structure is there.  


Not quite. He is using the event structure to prevent the loop from spinning.  He starts with timeout = 0 so it will execute once, and then sets the timeout to -1 so it only updates on a value change - something that producer/consumer architecture does by default.

 

As for putting it in to a producer/consumer form, there is a template example you can start from.  Make a new project, go to templates, and select "Queued Message Handler".  You should be able to gut the "Main.vi" it builds, and dump your code in to the lower "consumer" loop.

0 Kudos
Message 3 of 12
(797 Views)
Highlighted

You're right, it does simply initialize everything then wait for an input.  He still needs to learn how to use the event structure correctly.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 4 of 12
(789 Views)

@kbbersch wrote:

You're right, it does simply initialize everything then wait for an input.  He still needs to learn how to use the event structure correctly.

 


Don't beat the OP up Kelly.  Event programming does break dataflow.  Its hard enough to teach a dataflow paradigm- teaching when and how to break dataflow is a bit more advanced.

Always maintain an accurate count of deployed mousetraps.
Message 5 of 12
(782 Views)

Didn't mean to sound like I was bearing him up. Sorry about that. I just think it needs to be put together better before he jumps into producer/consumer. Get the details right on what he's got now and it will be easier to learn how to transition it.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 6 of 12
(765 Views)

 Kelly,

 

I am not sure what you meant on  using shift registers to transfer data from one iteration to the next. Can you please clarify that? I have attached another attempted on the mutlidimensional fit. 

 

P.S. By the way i'm a female.

 

Thanks, 

 

Ynessa Tran

Electrical Engineering Student

0 Kudos
Message 7 of 12
(756 Views)

I'll let Kelly speak to the Shift Register subject. 

 

Hmmmm... I know a lot of "Kellys" ,"Chris's" (Or Cris's), "Pats" and a few "Sams" Is gender that important?

 

On the other hand I will ask you to look at the "Fit Button" Boolean.  You have it coded as:

 

If "Fit Button" value equals "True" then assign a value to "Fit Button" of "False"   Otherwiswe, "Fit Button" should be assigned a value of "False"

 

Yup, that could probably be handled betterSmiley Wink  Try changing the Mechanical action on "Fit Button" to "Latch When released" and give the value change of Fit Button its own event case.

Always maintain an accurate count of deployed mousetraps.
0 Kudos
Message 8 of 12
(749 Views)

@ytran wrote:

I have created this labview code called '2D Fit.VI' without any DAQ hardware that will create a mutlidimensional fit, is it possible to put this VI in a Producer/Consumer format? If so how would I approach it?  The VI's are attached below. 

 

Thanks. 


I assume you have already read the white paper on Producer/Consumer.  I would start by turning the code inside of the event structure into a subVI.  I will be a lot easier to move around then.

 

Then you just make a queue that can hold new data and read the queue in the consumer loop.  Give it a try first and then post what you have.  We can help you a lot more from there.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 9 of 12
(731 Views)

Yes, give it a try and post what you end up with.  I'm still of the opinion that you need to straighten out the code in the event structure so you have what resembles a state machine before you move to producer/consumer.  What you have tries to do everything with one event when you should have one for each control (but not indicators).  Once that's corrected I think moving to producer/consumer will be much easier.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
Message 10 of 12
(709 Views)