03-25-2011 12:18 PM
Hi everyone,
I am not sure if I get the producer/consumer concept wrong. I tried to write a producer/consumer subvi that simulate continuously grab acquire image. When I call the subvi from the main while loop with a main vi, it seems to run into a infinite loop. I am wondering does anyone know how else can I activate a producer/consumer subvi using main vi? Thanks in advance.
Kind regards,
Han Yen
Solved! Go to Solution.
03-25-2011 12:26 PM
I was working on something similar a few days ago. And I stumbled upon this example:
http://zone.ni.com/devzone/cda/epd/p/id/5859
Probably kind of similar to your code. Hope this helps a bit.
03-25-2011 01:49 PM
thanks a lot, josborne..I'll look through the the example and see how it works. 🙂
03-25-2011 02:23 PM
Actually, it seems that the button in the subvi does not respond to the one in the main vi. Perhaps I did not pass the data from the main vi into the subvi properly.
03-26-2011 09:50 AM
Hi Han Yen,
a few remarks :
- your Top VI has no function what so ever. So skip that.
- your image queue has no name, so that gives problems from the minute you're going to use more queues.
- It does not matter which command you send to the queue, it will start the bottom loop anyway
- You don't have a check whether "live trial" is true yes or no, so everytime you switch it from T=>F or F=>T is will activate the command.
I've tweeked your producer-consumer. Maybe this will give you an idea. I put some remarks in some places
03-26-2011 09:52 AM
@Han Yen wrote:
Actually, it seems that the button in the subvi does not respond to the one in the main vi. Perhaps I did not pass the data from the main vi into the subvi properly.
of course it does not respond. This will never work that way. In this case, your top level VI has NO use. Don't make it too hard on yourself. Why do you want to use a top level VI if it's not needed.
03-26-2011 12:22 PM
Dear Bjorn,
Thank you very much for the feedback and comments. They are very helpful. Actually, at the top level I have other functions too. But I haven't implement them yet. The other functions I plan to implement is snap image, save image, monitor camera temperature, adjust camera gain and update, adjust stage control.., etc.
The current subvi "ProducerConsumerGrab" is to try to get most recent image from my Andor high speed camera with while loop. It's like the Grab function in IMAQ. I can't use the some IMAQ grab acquire functions because my camera is incompatible with NI. The basic Andor library do have basic functionality. So, I thought if I am able to pass the signal from button at the top level, into the subvi "ProducerConsumerGrab", I can also do so for the other functions I mentioned earlier.
Do you think is a good approach?
With thanks,
Han Yen
03-26-2011 02:02 PM
Hi Han Yen,
I don't think you totally understand the idea behind producer-consumer loops.
Consumer-producer is normally ment to have a user-interface loop and another loop (like you camera loop) without having the UI to wait for the cam loop.
You don't have to create a new prod-cons structure for every VI if you can do all the actions in one.
I've changed the prod-cons loop to show you how it's done. It's really easy once you get the hang of it.
If you have any questions, don't hesitate to ask.
03-26-2011 02:11 PM
Bettter use this one. The one above had a "small" error
03-29-2011 02:23 PM
Hi Bjorn,
Thank you very much for your comments and guidance. It works great. I think I sort of understand much better on how to use the producer/consumer architecture. 🙂
Kind regards,
Han Yen