LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel loop timing

 

I am trying to make a VI that runs a program after a delay when a value goes out of range. It is working for the most part, which is great, but it always runs the program at least twice. Could someone please help me figure out why it always runs the program twice? Any other suggestions to make it better would be great as well. The block diagram is attached. I thank you in advance.

 

 

0 Kudos
Message 1 of 17
(3,500 Views)

Please do not post pictures of code, post the code itself (i.e. attach your VI).  This allows us to view it without needing magnifiers, and (more important) to run your code, noting (and possibly fixing) errors.

 

Bob Schor

Message 2 of 17
(3,479 Views)

Sorry, I have only posted a couple of times, so am new at this. Attached is my VI.

0 Kudos
Message 3 of 17
(3,473 Views)

OK, I looked at the picture (I'm sending you the bill for Eye Strain).  You have two parallel loops with no real communication between them except through Local Variables (which is a Bad Idea due to Race Conditions -- this is probably why you have an extra loop).

 

What you probably want is a Producer/Consumer pattern.  Your top loop is the Producer -- it decides when (or if) a Phone Call should be placed.  If so, it puts it on a Queue and sends it to the bottom, Consumer, loop.  This loop doesn't need any "waiting"or "elapsed time expired" -- when the Producer says "Make the call" (after the Producer notes that the elapsed time has expired), the Consumer sees the request in the Queue, dequeues it, and makes the call.

 

There are numerous examples of this Pattern, including going to File, New, and choosing From Template, Producer/Consumer Design Pattern.

 

Bob Schor

Message 4 of 17
(3,470 Views)

Using a notification would be better than local variables for this application.

 

Try the attached application and see if it's still calling the executable twice. If it is, you might want to verify that your elapsed timer is resetting correctly.

 

Edit: As Bob mentioned, queues would also work. My implementation is a (far) less scalable producer/consumer pattern.

Message 5 of 17
(3,458 Views)

Thank you for posting a revised VI for me, however I am using LabVIEW 2010 so I am unable to run the VI. Could you please change it so it can be run on LabVIEW 2010?

0 Kudos
Message 6 of 17
(3,436 Views)

Yes sir!

 

Sorry about that.

Message 7 of 17
(3,432 Views)

Thank you, that makes more sense than the way I was doing it. However, it still calls the callPCI.vi twice.

0 Kudos
Message 8 of 17
(3,406 Views)

As a quick bandaid solution to the original code, all you need is configure the elapsed time express VI to auto-reset. This way the "elapsed" boolean is no longer true on the next iteration.

 

And please get rid of the LCC commercial power local variable and use a wire. You are creating a race condition because you are most likely processing a stale value while the new value is written in parallel.

 

Personally, I would usee a queue, not a notifier. This way the entry disappears when it is consumed.

0 Kudos
Message 9 of 17
(3,376 Views)

I have tried using a queue, however it constantly runs CallPCI.vi.

 

The notifier runs CallPCI.vi twicw, even if I set the elapsed time to auto-reset.

 

Overall I need to do this for about 40 different signals, so your help getting the first one to work is very appreciated.

 

Any suggestions?

Download All
0 Kudos
Message 10 of 17
(3,234 Views)