LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping While Loop NI Vision Acquisition

Hi all , 

 

I'm trying to design simple VI to display/capture /images/videos. I managed to program - "open image/avi videos".

The next stage is to display the video coming from my built-in cam in my laptop. 

Each button is associated to event case, and when i'm pressing "show video" i'm abling to see the video, but I can't stop the "video stream" or stop the entire VI, looks like I can't press with perfect timing (which isn't the aim) on the "stop vid" button. 

 

any advices ... ?

 

attached the vi

0 Kudos
Message 1 of 10
(4,199 Views)

Hi Udi,

 

The trouble you are having is due to the while loop being within the event structure. Once you press "Show Video" it stays within the while loop that grabs the image until you press "Stop Acq".

 

You might want to try using shift registers on the outer while loop for the IMAQ references with the "grab.vi" in the timeout? Or something similar that uses the timeout of the event structure instead of a while loop within a while loop.

 

Hope it helps

0 Kudos
Message 2 of 10
(4,177 Views)

I tried to seperate the code into two while loops master/slave using notifiers, but it seems that something is wrong with code as I am not able to send the notification correctly. 

 

When I am pressing the show video button first , the code turn the camera on and start to grab frame (with slow rate , why ?) , then I want to stop and close the camera when I press "stop video" which should send notify to the slave loop , and it isn't doing it. 

 

also vice versa if I press first "stop video" (altough there isn't video) , and then I am pressing "show video" the notification isn't send. 

 

any ideas? 

 

Download All
0 Kudos
Message 3 of 10
(4,130 Views)

As they say, "Close, but no cigar".  You almost have the right idea of Producer/Consumer with Event structure.  Here's a suggestion:

 

Create a different Enum, call it "State".  Have it take on the following values:  "Show Video", "Stop Video", "Open Video", "Open Button", and "Quit".  Create a Queue (not a Notifier) for this Enum.  [Why a Queue instead of a Notifier?  A Notifier only "remembers" the last item, so if you push two buttons at the same time, you might not "see" both of them].  [Another thing to think about -- what if you push Start Video twice in a row, without pushing Stop Video in between?  What do you want to have happen?].

 

Make your Event loop very tiny -- the only thing it should do is to Enqueue the appropriate Enum value -- it should not do any other processing!  [Possible exception -- you could have the Stop button Value Change case not only put "Quit" on the Queue, which should be set to stop the Consumer loop, but, as a "side effect", it can stop the Producer loop, too.  This means you don't need "Stop2"].

 

Now put all the "Action code" currently in your Event Loop in the Consumer Loop (you currently have Show Video and Stop Video code there -- put the Open Video and Open Image code there, as well).

 

Notice that you've relegated to the Event loop only "Events", things that happen randomly and unpredictably (like users pushing buttons), so very little time is spent here.

 

If you want to make this even more "transparent" to experienced LabVIEW programmers, put the Event loop on top (and, as noted above, make it tiny).

 

Bob Schor

 

 

0 Kudos
Message 4 of 10
(4,123 Views)

I'll take your advice and replace the notifier to queue.

 

"Another thing to think about -- what if you push Start Video twice in a row, without pushing Stop Video in between?  What do you want to have happen?"

 

The answer is that I want that the code will continue to run like nothing happend , so should I check in which state I'm in ? 

 

 

Still I don't understand why the button isn't functioning appropriately, I if turn debug mode and press "show video" than after I am pressing on the "stop video" , I can see that the enum state "stop video" goes into "Send Notification" , but not extracted from the "wait to notification" (this happens from the second press on "show/stop video" alternately).

 

as for the order I accidenatly clicked on the clean up saved and quit... 😕 

0 Kudos
Message 5 of 10
(4,110 Views)

I did a mistake , I should have insert the De-queue or the Wait to Notification into the slave while loop. 

 

Now the events are working , but the video is continous seems like the slave while run for 1 iteration each time I'm pressing "Show Video"

0 Kudos
Message 6 of 10
(4,088 Views)

Which version of LV are you using? I have a subVI that might help you

0 Kudos
Message 7 of 10
(4,079 Views)

2013

0 Kudos
Message 8 of 10
(4,077 Views)

 

I did a mistake , I should have insert the De-queue or the Wait to Notification into the slave while loop. 

 

Now the events are working , but the video isn't run smoothly,  seems like the slave while run for 1 iteration each time I'm pressing "Show Video"

 

*Is it possible to edit my posts here ? 

Download All
0 Kudos
Message 9 of 10
(4,073 Views)

Hopefully this zip file should help, if you copy the while loop from the Camera(subVI).vi and paste it into your code then add the commands and things so that the camera is initialised correctly. It does make an AVI recording of the video so you might want to tweak the code or create your with this as a template.

 

Hope it helps.

 

It currently has an array of camera references going into the initialisation but only looks at the first index.

0 Kudos
Message 10 of 10
(4,063 Views)