02-12-2014 11:11 AM
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.
02-12-2014 02:34 PM
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.
02-12-2014 04:16 PM
@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.
02-12-2014 04:30 PM
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.
02-12-2014 04:36 PM
@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.
02-12-2014 05:25 PM
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.
02-12-2014 06:04 PM
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
02-12-2014 06:27 PM
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 better Try changing the Mechanical action on "Fit Button" to "Latch When released" and give the value change of Fit Button its own event case.
02-13-2014 07:19 AM
@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.
02-13-2014 04:24 PM
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.