07-02-2015 10:35 AM
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.
07-02-2015 11:09 AM
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
07-02-2015 11:17 AM
Sorry, I have only posted a couple of times, so am new at this. Attached is my VI.
07-02-2015 11:18 AM
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
07-02-2015 11:24 AM - edited 07-02-2015 11:26 AM
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.
07-02-2015 11:39 AM
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?
07-02-2015 11:42 AM
Yes sir!
Sorry about that.
07-02-2015 12:13 PM
Thank you, that makes more sense than the way I was doing it. However, it still calls the callPCI.vi twice.
07-02-2015 01:20 PM
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.
07-06-2015 12:56 PM
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?